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
output : name
either table, record, or DataSeries. Specifies the data structure to use for parsed data corresponding to JSON objects (collections of key/value pairs). With output=table (the default), an object is encoded as table; with output=record, it is encoded as a record; with output=DataSeries, it is encoded as a DataSeries.
The ParseString(jsonString) command 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⁡count=23,fruit=orange
myTable["fruit"];
orange
Parse the same input string to a Maple record.
myRecord := ParseString("{\"fruit\": \"orange\", \"count\": 23}",output=record);
myRecord≔Recordpacked⁡count=23,fruit=orange
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,name=Bangalore,country=India,table⁡population=10125000,name=Kinshasa,country=Democratic Republic of the Congo,table⁡population=2229621,name=Paris,country=France,table⁡population=13617445,name=Tokyo,country=Japan
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 2016.
See Also
JSON[ParseFile]
JSON[ToString]
Download Help Document
What kind of issue would you like to report? (Optional)