JSON - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Connectivity : Web Features : JSON : JSON/ParseString

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}]"; Cities := JSON:-ParseString(CityData); seq( city["name"], city in Cities );

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

Citiestablecountry=India,name=Bangalore,population=8443675,tablecountry=Democratic Republic of the Congo,name=Kinshasa,population=10125000,tablecountry=France,name=Paris,population=2229621,tablecountry=Japan,name=Tokyo,population=13617445

Bangalore,Kinshasa,Paris,Tokyo

(5)

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]