ParseString - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.
Our website is currently undergoing maintenance, which may result in occasional errors while browsing. We apologize for any inconvenience this may cause and are working swiftly to restore full functionality. Thank you for your patience.

Online Help

JSON

  

ParseString

  

parse a string containing JSON data

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

ParseString(jsonString, opts)

Parameters

jsonString

-

string; JSON data

opts

-

(optional) options as specified below

Options

• 

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.

Description

• 

ParseString(jsonString) parses the input string jsonString, which is assumed to be valid JSON.

Examples

Parse a JSON string to a Maple table.

with(JSON):

myTable := ParseString("{\"fruit\": \"orange\", \"count\": 23}");

myTabletablefruit=orange,count=23

(1)

myTable["fruit"];

orange

(2)

Parse the same input string to a Maple record.

myRecord := ParseString("{\"fruit\": \"orange\", \"count\": 23}",object=record);

myRecordRecordpackedfruit=orange,count=23

(3)

myRecord["fruit"];

orange

(4)

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}]

(5)

Cities := JSON:-ParseString(CityData);

Citiestablepopulation=8443675,country=India,name=Bangalore,tablepopulation=10125000,country=Democratic Republic of the Congo,name=Kinshasa,tablepopulation=2229621,country=France,name=Paris,tablepopulation=13617445,country=Japan,name=Tokyo

(6)

seq( city["name"], city in Cities );

Bangalore,Kinshasa,Paris,Tokyo

(7)

Compatibility

• 

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

JSON[ParseFile]

JSON[ToString]

 


Download Help Document