splitJsonObjects
splitJsonObjects(json: String) : List<String>
Splits a string containing multiple JSON objects into an ordered list of individual JSON object strings.
- This function is useful when parsing output that contains multiple JSON objects concatenated together.
- The returned list preserves the order in which the JSON objects appear in the input string.
Example
jsonText = """
{"name": "device1", "status": "up"}
{"name": "device2", "status": "down"}
{"name": "device3", "status": "up"}
""";
foreach objectString in splitJsonObjects(jsonText)
let actualJSON = extractJson[{name: String, status: String}](objectString)
let status = actualJSON.status
select actualJSON
order by status ascending
Notice that splitJsonObjects returns individual objects as Strings, but if we want them as typed records then we use
the extractJson function.
See also
Guides
- JSON - Working with JSON data
- Collections - Working with collections
- String
Functions
- extractJson - Extract typed data from JSON strings