Tinderbox v9 Icon

JSON.json[keyStr]


Operator Type: 

Operator Scope of Action: 

Operator Purpose: 

Operator First Added: 

Operator Last Altered: 

 Function  [other Function type actions]

 Item  [operators of similar scope]

 Stream parsing  [other Stream parsing operators]

 Baseline

 9.6.0


JSON.json[keyStr]

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. keyStr is a quoted key name and [ ] square brackets, not ( ) parentheses must be used to pass keyStr. Be aware of possible operator name confusion as described in the Notes section further below.

If the top-level element is an object, Stream.json[key] returns a dictionary for that object. If the top-level element is an array, see JSON.json[itemNum].

For example if $Text is:

{ "title":"Becket", "price": 9.95 } 

and $Subtitle is set to "title", then:

$Text.json["title"]; is "Becket".

$Text.json[title]; is "Becket".

$Text.json["price"]; is "9.95".

$Text.json['$Subtitle']; no such field.

$Text.json[$Subtitle]; is "Becket".

Though from v9.6.0 multiple bracketed arguments can be used to address a JSON path, consider use of .jsonValue(pathStr) instead. For example:

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

Then:

$Text.json['person']['lastName'] gives 'Roe'

But, easier:

$Text.json.jsonValue(person.lastName) gives 'Roe'

$Text.json.jsonValue($MyString) gives 'Roe' (from v9.6.0)

Again, using the same JSON as above:

$MyString="coordinates"; 

Now

$Text.json['coordinates'][0] gives -90 (from v9.6.0)

$Text.json[$MyString][1] gives 41 (from v9.6.0)

Notes

Be aware: