Skip to content

Commit

Permalink
Merge pull request #238 from arorajatin/master
Browse files Browse the repository at this point in the history
Add support for printing json format for Swift Dictionaries and Arrays
  • Loading branch information
kastiglione authored May 19, 2018
2 parents ccf8dd5 + 15ebceb commit 1ca4c58
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions commands/FBPrintCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def lldbcommands():
FBPrintData(),
FBPrintTargetActions(),
FBPrintJSON(),
FBPrintSwiftJSON(),
FBPrintAsCurl(),
FBPrintToClipboard(),
FBPrintObjectInObjc(),
Expand Down Expand Up @@ -492,6 +493,29 @@ def run(self, arguments, options):

print jsonString

class FBPrintSwiftJSON(fb.FBCommand):

def name(self):
return 'psjson'

def description(self):
return 'Print JSON representation of Swift Dictionary or Swift Array object'

def options(self):
return [ fb.FBCommandArgument(arg='plain', short='-p', long='--plain', boolean=True, default=False, help='Plain JSON') ]

def args(self):
return [ fb.FBCommandArgument(arg='object', type='NSObject *', help='The Swift Dictionary or Swift Array to print') ]

def run(self, arguments, options):
#Convert to NSObject first to allow for objc runtime to process it
objectToPrint = fb.evaluateInputExpression('{obj} as NSObject'.format(obj=arguments[0]))
pretty = 1 if options.plain is None else 0
jsonData = fb.evaluateObjectExpression('[NSJSONSerialization dataWithJSONObject:(NSObject*){} options:{} error:nil]'.format(objectToPrint, pretty))
jsonString = fb.evaluateExpressionValue('(NSString*)[[NSString alloc] initWithData:(NSObject*){} encoding:4]'.format(jsonData)).GetObjectDescription()

print jsonString

class FBPrintAsCurl(fb.FBCommand):
def name(self):
return 'pcurl'
Expand Down

0 comments on commit 1ca4c58

Please sign in to comment.