AppleScript JSON encoder
AppleScript Makefile
Switch branches/tags
Nothing to show
Clone or download
mgax Merge pull request #4 from claui/combining-characters
Add support for combining characters
Latest commit ad86475 Sep 8, 2017

README.md

AppleScript JSON encoder

AppleScript lacks a native way to generate JSON, which makes getting data out of scripts difficult. This script provides a basic JSON encoding capability, to serialize strings, integers, lists and dictionaries.

Installation

Build the json.scpt file by running make, copy it next to your script, and import it with the following code:

tell application "Finder"
    set json_path to file "json.scpt" of folder of (path to me)
end
set json to load script (json_path as alias)

Alternatively, just copy/paste the contents of json.applescript into your own script, and use it straight away.

Usage

To encode strings, numbers and lists:

json's encode("hellø world")
-- "hell\u00f8 world"

json's encode(13)
-- 13

json's encode({1, "2", {3, 4}})
-- [1, "2", [3, 4]]

Dictionaries are supported via a wrapper object:

set my_dict to json's createDict()
my_dict's setkv("hello", {"world", 13})
json's encode(my_dict)
-- {"hello": ["world", 13]}

set my_dict_2 to json's createDictWith({ {"foo", "bar"}, {"baz", 22} })
json's encode(my_dict_2)
-- {"foo": "bar", "baz": 22}