|
Calling Sequence
|
|
ParseString(jsonString, opts)
|
|
Parameters
|
|
jsonString
|
-
|
string; JSON data
|
opts
|
-
|
(optional) options as specified below
|
|
|
|
|
Options
|
|
|
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.
|
|
|
Description
|
|
•
|
ParseString(jsonString) parses the input string jsonString, which is assumed to be valid JSON.
|
|
|
Examples
|
|
Parse a JSON string to a Maple table.
>
|
myTable := ParseString("{\"fruit\": \"orange\", \"count\": 23}");
|
| (1) |
Parse the same input string to a Maple record.
>
|
myRecord := ParseString("{\"fruit\": \"orange\", \"count\": 23}",object=record);
|
| (3) |
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}]";
|
| (5) |
>
|
Cities := JSON:-ParseString(CityData);
|
| (6) |
>
|
seq( city["name"], city in Cities );
|
| (7) |
|
|
Compatibility
|
|
•
|
The JSON[ParseString] command was introduced in Maple 2015.
|
•
|
The JSON[ParseString] command was updated in Maple 2022.
|
•
|
The array and object options were introduced in Maple 2022.
|
|
|
|