ParseJSON
New to Analytica 5.0
This function requires the Analytica Enterprise edition or higher (e.g., Analytica Optimizer, ADE or CubePlan).
ParseJSON( json, objectSchema..., flags )
Parses JavaScript Object Notation (JSON) text in «json» and returns the parsed data. Parsing can be done with or without using «objectSchema». The «objectSchema», if used, helps you map the structure of the data onto indexes of your model.
The «json» text will most commonly be obtained from a call to ReadTextFile or ReadFromUrl.
Parameters
- «json»: Text containing the JSON-formatted text to parse.
- «objectSchema»: Zero or more schemas, where each schema describes the JSON class structure and the Analytica index that it maps onto. See Parsing with a schema. When no «objectSchema» is provided, «json» is parsed without a schema. See Parsing without a schema.
- «flags»: (optional) A bit field of flags that control various aspects of parsing. Bit settings are
- 1 = During schema-free parsing, create local indexes
.Dim1
,.Dim2
, ... for arrays. Without this, each level of an array is returned as a reference to a list.
- 1 = During schema-free parsing, create local indexes
Parsing without a schema
When the «objectSchema» parameter is not specified,
ParseJSON( json )
parses the «json» data without using a schema.
Reading JSON objects
The top-level item in a JSON document should be a JSON-object. Here is an example of a JSON object.
Variable json1 Definition: '{ "title" : "1984", "author" : "George Orwell", "year" : 1949, "pages" : 336, "paperback" : true }'
ParseJSON(json1)
→
Notice that a local index named .Member
is automatically created. The 'title'
is text, the 'year'
is a number.
- Variable parse1a :=
ParseJSON(json1)
TypeOf(parse1a[.Member='title']) → 'Text'
TypeOf(parse1a[.Member='year']) → 'Number'
When there are nested objects, local indexes are created at each level. To prevent the indexes from combining into a rectangular array, the member object is placed within a reference.
Variable json2 Definition: '{ "title" : "1984", "author" : { "first" : "George", "last" : "Orwell" }, "year" : 1949, "pages" : 336, "paperback" : true }'
Enable comment auto-refresher