JsonGet - Script and chart function
JsonGet() returns the path of a JSON (JavaScript Object Notation) data string. The data must be valid JSON but can contain extra spaces or newlines.
Syntax:
value JsonGet(json, path)
Return data type: dual
| Argument | Description |
|---|---|
| json | String containing JSON data. |
| path |
The path must be specified according to RFC 6901. This will allow lookup of properties inside JSON data without using complex substring or index functions. |
| Example | Result |
|---|---|
| JsonGet( '{"a":{"xyz":"XYZ"},"b":[123,"abc","ABC"]}', '' ) | Returns {"a":{"xyz":"XYZ"},"b":[123,"abc","ABC"]} |
| JsonGet( '{"a":{"xyz":"XYZ"},"b":[123,"abc","ABC"]}', '/a' ) | Returns {"xyz":"XYZ"} |
| JsonGet( '{"a":{"xyz":"XYZ"},"b":[123,"abc","ABC"]}', '/a/xyz' ) | Returns "XYZ" |
| JsonGet( '{"a":{"xyz":"XYZ"},"b":[123,"abc","ABC"]}', '/b' ) | Returns [123,"abc","ABC"] |
| JsonGet( '{"a":{"xyz":"XYZ"},"b":[123,"abc","ABC"]}', '/b/0' ) | Returns 123 |
| JsonGet( '{"a":{"xyz":"XYZ"},"b":[123,"abc","ABC"]}', '/b/1' ) | Returns abc |
| JsonGet( '{"a":{"xyz":"XYZ"},"b":[123,"abc","ABC"]}', '/b/2' ) | Returns ABC |
| JsonGet( '{"a":"b"}','/b' ) | Returns null. The path does not point to a valid part of the JSON data. |
| JsonGet( '{"a"}','/a' ) | Returns null. The JSON data is not valid JSON (member "a" does not have a value). |
Example - JsonGet fundamentals
See also: