Logo

DP-2 with added JSON

Now available! LiveCode Create DP-2 for Cloud, Native and Universal.

We’ve been working hard cleaning up code, fixing bugs and making the Create experience better. We also have one, much requested, addition for you: faithful & fast JSON.

There are two new functions jsonEncode(<value>) and jsonDecode(<string>) which convert a LiveCode value to and from a JSON formatted string with minimal whitespace.

Encoding of values is substantially better than any other existing LiveCode JSON encoding solution. The functions use lower-level type information to determine what kind of JSON value to generate. and numbers are encoded using the ECMAScript rules meaning that they will be emitted the same as they are when encoding as JSON from JavaScript.

Decoding of values is similarly substantially better than any other existing LiveCode JSON decoding solution. JSON values are decoded to LiveCode values tagged with lower-level type information.

The main outcome of this that LiveCode values will ’roundtrip’ through JSON identically. In particular, values such as [] and {} will encode to and from [] and {}, and it is possible to distinguish between [1,2] and {“1″:1,”2”:2}.

Finally, the performance of the new functions is substantially better than any currently existing alternative.

 

Performing a simple benchmark on a 25Mb JSON file (on an Intel mac) containing a mixture of numbers, strings (both unicode and ascii), arrays and objects to several levels of nesting results in the following:

Functions

Implementation

Encode
Decode

jsonEncode/jsonDecode

Engine

0.14s

0.75s

ArrayToJSON/ArrayFromJSON

mergJSON

4.8s

5.1s

JsonExport/JsonImport*

JSON Library

25.5s

189s

JSONStringify/JSONParser

PhotonJSON

2.7s

6.7s

Python3

built-in

0.22s

0.25s

Node (JavaScript)

built-in

0.1s

0.19s

* These timings are for the JSON Library implementation in LiveCode 10, in Create 1.0-dp-2, the existing JSON Library has been re-implemented using the builtin engine functions.

Overall, the new JSON support is 20x faster at encoding than the nearest alternative, and 7x faster at decoding – with times for encoding comparable to Python and JavaScript (decoding we’ve still got a bit more work to do to catch up!).

Building on the built-in engine support are further json related functions in the rewritten JSON Library including functions for encoding as ASCII, encoding and decoding as UTF-8 and encoding in a human-readable form.