Skip to content

Instantly share code, notes, and snippets.

@tLewisII
Created July 21, 2014 00:11
Show Gist options
  • Save tLewisII/c1ac2c3ef7d1f509acc7 to your computer and use it in GitHub Desktop.
Save tLewisII/c1ac2c3ef7d1f509acc7 to your computer and use it in GitHub Desktop.
JSON Lens traversal in Swift
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