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 | JSL | Notes |
---|
array | list | sequence of values |
object | associative array | set of named values |
number | number | |
string | string | |
true | 1.0 | |
false | 0.0 | |
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
{"region":"Europe",
"country":[
{"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
country.name | country.population | region |
---|
France | 66.1 | Europe |
Germany | 80.8 | Europe |
Note that the region value gets repeated.
Implementation notes
Please report issues to the File Exchange discussion or to xan.gregg@jmp.com.
Update: I've also attached Craige's JSON Parser II.jsl, which is a much much faster version of JSON Parser.jsl.