Skip to content

Instantly share code, notes, and snippets.

@jparishy
Created September 19, 2013 20:20
Show Gist options
  • Save jparishy/6629273 to your computer and use it in GitHub Desktop.
Save jparishy/6629273 to your computer and use it in GitHub Desktop.
Print JSON from LLDB
...
command script import ~/.lldb/print_json.py
# Then restart Xcode
(lldb) pj @{ @"Hello" : @"World!" }
$1 = 0x13278bf0 {"Hello":"World!"}
(lldb)
#!/usr/bin/env python
# Goes in ~/.lldb/print_json.py
import lldb
import commands
def print_json(debugger, command, result, internal_dict):
lldb.debugger.HandleCommand("po [[NSString alloc] initWithData:(id)[NSJSONSerialization dataWithJSONObject:(" + command + ") options:0 error:nil] encoding:4]")
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand("command script add -f print_json.print_json pjson")
print "print_json installed."
@Noreaster76
Copy link

@jparishy Looks great, but how would you modify the above to pretty print it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment