Tinderbox v10 Icon

JSON processing

Tinderbox can process JSON stored in any string attribute, including $Text, or String-type variable. JSON dot-operators are expecting the whole contents of the stream to be a valid JSON object.

JSON.json[key]

If there is no current JSON object, attempts to parse the string as JSON and fails if unsuccessful. If there is a current JSON object, that object will be reused. If the top-level element is an object, JSON.json[key] returns a dictionary for that object.

JSON.json[N]

If there is no current JSON object, attempts to parse the string as JSON and fails if unsuccessful. If there is a current JSON object, that object will be reused. If the top-level element is an array, JSON.json[N] returns the Nth object.

JSON.json.each{action}

If the top-level element is an array, rebinds the JSON object in turn to each array element. After calling the action block for each element, the JSON object is restored.

JSON.jsonValue().

String.captureJson()

Attempts to parse the Stream's string and re-scope it as the full contents of (only the first) JSON code detected within the text. It fails if unsuccessful.

JSON property chaining

JSON doesn't have a formal pathing method like XPath in XML, but JSON properties can be chained to allow navigation to nested objects. For example, consider:


{
  "person": { "firstName": "Thomas", lastName: "Roe"},
  "coordinates" : [-90,41]
}

Thomas’s latitude can be addressed via

$Text.json["coordinates"][0] 

And his family name via

$Text.json["person.lastName"]

See also—notes linking to here: