ParseString - Maple Help

Online Help

All Products    Maple    MapleSim


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

• 

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.

Description

• 

The ParseString(jsonString) command 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}");

myTabletablecount=23,fruit=orange

(1)

myTable["fruit"];

orange

(2)

Parse the same input string to a Maple record.

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

myRecordRecordpackedcount=23,fruit=orange

(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,name=Bangalore,country=India,tablepopulation=10125000,name=Kinshasa,country=Democratic Republic of the Congo,tablepopulation=2229621,name=Paris,country=France,tablepopulation=13617445,name=Tokyo,country=Japan

(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 2016.

See Also

JSON

JSON[ParseFile]

JSON[ToString]