Skip to content
AppleScript JSON encoder
AppleScript Makefile
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE.txt
Makefile
README.md
json.applescript
tests.applescript

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}
You can’t perform that action at this time.