JSON
ParseString
parse a string containing JSON data
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
ParseString(jsonString, opts)
jsonString
-
string; JSON data
opts
(optional) options as specified below
array : list or Array
Specifies the data structure to use for parsed data corresponding to JSON arrays (sequential data delimited with square brackets). With array=list (the default), a JSON array is encoded as a list; with array=Array, it is encoded as an Array.
object : one of equationset, DataSeries, record, or table
Specifies the data structure to use for parsed data corresponding to so-called JSON objects. These are collections of key/value pairs which when encoded in JSON are enclosed in curly braces ({}). The option affects any JSON objects in the input, but not other types of structured data, such as lists.
With object=table (the default), an object is encoded as table; with object=record, it is encoded as a record; with object=DataSeries, it is encoded as a DataSeries; with object=equationset, it is encoded as a set of equations.
output : one of equationset, DataSeries, record, or table
A legacy alias for the object option. Its behavior is identical to that of object.
ParseString(jsonString) parses the input string jsonString, which is assumed to be valid JSON.
Parse a JSON string to a Maple table.
with(JSON):
myTable := ParseString("{\"fruit\": \"orange\", \"count\": 23}");
myTable≔table⁡fruit=orange,count=23
myTable["fruit"];
orange
Parse the same input string to a Maple record.
myRecord := ParseString("{\"fruit\": \"orange\", \"count\": 23}",object=record);
myRecord≔Recordpacked⁡fruit=orange,count=23
myRecord["fruit"];
Parse a JSON string to a list of tables.
CityData := "[{\"name\": \"Bangalore\", \"population\": 8443675, \"country\": \"India\"}, {\"name\": \"Kinshasa\", \"country\": \"Democratic Republic of the Congo\", \"population\": 10125000}, {\"name\": \"Paris\", \"country\": \"France\", \"population\": 2229621}, {\"name\": \"Tokyo\", \"country\": \"Japan\", \"population\": 13617445}]";
CityData≔[{"name": "Bangalore", "population": 8443675, "country": "India"}, {"name": "Kinshasa", "country": "Democratic Republic of the Congo", "population": 10125000}, {"name": "Paris", "country": "France", "population": 2229621}, {"name": "Tokyo", "country": "Japan", "population": 13617445}]
Cities := JSON:-ParseString(CityData);
Cities≔table⁡population=8443675,country=India,name=Bangalore,table⁡population=10125000,country=Democratic Republic of the Congo,name=Kinshasa,table⁡population=2229621,country=France,name=Paris,table⁡population=13617445,country=Japan,name=Tokyo
seq( city["name"], city in Cities );
Bangalore,Kinshasa,Paris,Tokyo
The JSON[ParseString] command was introduced in Maple 2015.
For more information on Maple 2015 changes, see Updates in Maple 2015.
The JSON[ParseString] command was updated in Maple 2022.
The array and object options were introduced in Maple 2022.
For more information on Maple 2022 changes, see Updates in Maple 2022.
See Also
JSON[ParseFile]
JSON[ToString]
Download Help Document