facebook/chisel

pjson not returning expected value with Swift

dlo opened this issue · 10 comments

dlo commented

Using the latest version of chisel from Homebrew. When I use pjson on a [String: String] dictionary in Swift, it doesn't appear to work.

(lldb) pjson response 
error: error: use of undeclared identifier 'response'
error: error: use of undeclared identifier 'None'
None

Happy to help contribute a fix if this only works for Objective-C!

Does this work?

pjson `response`

I think this problem can be resolved by #228. If you'd like to try this on your machine, I can help you with that.

dlo commented

@kastiglione I'm going to check this out tomorrow morning. Thanks again for the quick change! You are awesome!

dlo commented

@kastiglione Finally got around to testing master. :)

Here's the output I get with the latest change in #228:

(lldb) pjson `response`
error: error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x7f9dd97dde90).
The process has been returned to the state before expression evaluation.
error: error: use of undeclared identifier 'None'
None

It's weird that I see an EXC_BAD_ACCESS, since po response works as expected.

dlo commented

FWIW, here's my pjson function in my existing .lldbinit. This one works as expected:

command regex ppjson 's/(.+)/po print(NSString(data: JSONSerialization.data(withJSONObject: %1, options: .prettyPrinted), encoding: String.Encoding.utf8.rawValue))/'

Do the changes in #228 work without the backticks?

pjson response

The backticks was a workaround suggestion to try, but then I opened the pull request which I expected would fix the bug.

dlo commented

I think there are two problems here. One is fixed by #228, but the other is a need to handle swift array/dictionary types. Either by adding some bridging casts, or as how you've done in the alias, by avoiding objc entirely and doing the conversion in swift. I'll have to try them and report back.

dlo commented

Sounds great, let me know if you'd like an extra hand.

This worked for me:

pjson json as NSDictionary
(There is a ` surrounding the json as NSDictionary part)