Subscribe Bookmark RSS Feed



Jun 23, 2011

JSON Parsing Functions

This JSL file contains functions for converting JSON text into either a JSL data structure or a JMP data table. JSON represents a structure of nested "arrays" and "objects". JSON types/values are represented as follows in JSL:

    JSON   JSLNotes
arraylistsequence of values
objectassociative arrayset of named values
null.missing value

When converted to a JMP data table, names represent columns and array values represent rows. Non-array values are filled down to match array values.

Main Functions

All functions are within the namespace "JSON" to avoid name collisions with other functions.

dt = JSON:Make Table( json text | obj )

obj = JSON:Parse( json text )

Example Data

Original JSON



         {"name":"France", "population":66.1},

         {"name":"Germany", "population":80.8}



Converted JSL

Associative Array(

   {{"country", {

      ["name" => "France", "population" => 66.1],

      ["name" => "Germany", "population" => 80.8]


   {"region", "Europe"}}


Note the order of the set elements is not preserved. It becomes alphabetical in JMP.

Values of the parsed object can be accessed with normal JSL subscripting. For example, if data holds the above parse result, you can access it with:

   data["country"][1]["name"];      // "France"

Converted Data Table


Note that the region value gets repeated.

Implementation notes

Please report issues to the File Exchange discussion or to

Update: I've also attached Craige's JSON Parser II.jsl, which is a much much faster version of JSON Parser.jsl.


Clever code Xan, using a JSL list as a stack to deal with the nested JSON structure is a great idea. 

Fast JSON Parsing using Pattern Matching  Faster variation of your code, still not well tested.

Thanks for pointing me at the Insert function, that was an important piece of the puzzle.


Great -- my 5 minute parse is now down to 1 second!

Article Tags