-
-
Save hsavit1/df1d08b57a2c82c87dc2 to your computer and use it in GitHub Desktop.
JSON Lens traversal in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let userjs: NSData = "{\"name\": \"max\", \"age\": 10, \"tweets\": [\"hello\"], \"attrs\": {\"one\": \"1\", \"more\": {\"stuff\": \"again\"}}}" | |
| .dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) | |
| let val = JSValue.decode(userjs) | |
| let traversal = JSValue.key("attrs") • JSValue.key("more") • JSValue.key("stuff") | |
| let getIt = traversal.get(val) | |
| let setIt = traversal.set(val, JSValue.JSString("bob")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment