This version is out of date, covering development from v9.5.0 to v9.7.3. It is maintained here only for inbound reference links from elsewhere. It is no longer actively updated.

Jump to the current version of aTbRef

Tinderbox v9 Icon

String.captureJSON()


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

 As at baseline


Syntax note: Operators without any defined mandatory arguments may omit their empty closing parentheses


String.captureJSON()

String.captureJSON

Attempts to parse the string as fully/partially JSON and fails if unsuccessful. The parsed JSON is saved as the current JSON (stream) object.

Essentially, this re-scopes the current stream so that it contains only the contents of the first section of JSON detected within the original stream. The focus of the stream parsing is set to the beginning of the extracted JSON code.

Only one JSON object may be current at any time. If the source stream contains multiple discrete JSON code sections, only the first is detected/used.

To actually work with the JSON data's values, use JSON.json[] and its sibling operators.

In the most likely scenario, working on $Text, .captureJSON() is needed only if $Text contains both JSON and other text:

$MyResult = $Text.captureJSON().json["somekey"]; 

But, if the whole of $Text is a single block of (complete) JSON, use .json[] directly. So:

$MyResult = $Text.json["somekey"];