JSON Helper Icon

Using JSON Helper

JSON Helper has three commands:

fetch JSON from

This parses JSON supplied by a url straight into an AppleScript record or list. Useful for interrogating web services directly from AppleScript. Optional basic HTTP authentication is supported if the web service requires it.

tell application "JSON Helper"

--Get UK police forces information

set forceDetails to fetch JSON from "http://policeapi2.rkh.co.uk/api/forces" name "apiname" password "apipassword"

end tell

tell application "JSON Helper"

--Monitor the public image Flickr feed:

set flickrFeed to fetch JSON from "http://api.flickr.com/services/feeds/photos_public.gne?format=json" with cleaning feed

set imageCount to count of |items| of flickrFeed

set lastModified to |modified| of flickrFeed

return ("Flickr feed has " & imageCount & " images, last modified at: " & lastModified)

end tell

tell application "JSON Helper"

--Look up a location in Google Maps:

set myLocation to "London"

set myRecord to fetch JSON from ("http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=" & myLocation)

set myResult to |ddURL| of item 1 of results of |responseData| of myRecord as string

tell application "Safari"

open location myResult

end tell

end tell

read JSON from

This parses JSON supplied as a string straight into an AppleScript record or list.

tell application "JSON Helper"

set myRecord to read JSON from "{\"cat\" : \"Socks\", \"colors\" : [\"black\",\"white\"], \"dog\" : \"Rover\", \"pets\" : true}"

return myRecord

end tell

make JSON from

This converts an AppleScript record or list onto a JSON string.

tell application "JSON Helper"

set myJSON to make JSON from {dog:"Rover", cat:"Socks", pets:true, colors:{"black", "white"}}

return myJSON

end tell

There will be times where JSON Helper can't create JSON from an AppleScript record or list, as it is not possible to map some of the values to an equivalent in the JSON. An example of this would be the following script.

tell application "TextEdit"

set teditProperties to properties

end tell

tell application "JSON Helper"

make JSON from teditProperties

end tell