Json Response with Applescript

How to Parse json response from Rest-Api using applescript?
There are scriptable third-party apps that can help with this but, if you want to avoid extra dependencies, you could use Foundation via ASOC. Here’s a small snippet to get you started:

Code Block
use framework "Foundation"
set NSJSONSerialization to current application's NSJSONSerialization
set NSString to current application's NSString
set NSUTF8StringEncoding to current application's NSUTF8StringEncoding
set jsonStr to "{ \"a\": \"b\" }"
set jsonNSStr to NSString's stringWithString:jsonStr
set jsonData to jsonNSStr's dataUsingEncoding:NSUTF8StringEncoding
set jsonRootDict to NSJSONSerialization's JSONObjectWithData:jsonData options:0 |error|:(missing value)
set aValue to jsonRootDict's objectForKey:"a"
aValue as string -- returns "b"


Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"
Json Response with Applescript
 
 
Q