Operator Type:
Operator Scope of Action:
Operator Purpose:
Data Type Returned:
Operator First Added:
Operator in Current Baseline:
Operator Last Altered:
Function [other Function type actions]
Item [operators of similar scope]
Stream parsing [other Stream parsing operators]
String [about String data type]
v9.1.0
Baseline
10.0.2
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"];
Legacy usage
Prior to v10.0.2, the operator used the casing .captureJSON(). This version is still silently supported (and is coloured in supported input boxes). However, .captureJson() is not the approved casing and existing code should be updated to this as legacy supprt may stop at any time.
See also—notes linking to here: