This function parses its first parameter (a string) as JSON, and returns the resulting sequence of objects and arrays.

parse-json($arg as string?) as json-item*

parse-json($arg as string?, $options as object) as json-item*

The object optionally supplied as the second parameter may contain additional options:

If parsing is not successful, an error is raised. Parsing is considered in particular to be non-successful if the boolean associated with "jsoniq-multiple-top-level-items" in the additional parameters is false and there is extra content after parsing a single abject or array.

Example 184. Parsing a JSON document

parse-json("{ \"foo\" : \"bar\" }", { "jsoniq-multiple-top-level-items" : false })

Result (run with Zorba): { "foo" : "bar" }

Example 185. Parsing multiple, whitespace-separated JSON documents

parse-json("{ \"foo\" : \"bar\" } { \"bar\" : \"foo\" }")

Result (run with Zorba): { "foo" : "bar" } { "bar" : "foo" }