Product SiteDocumentation Site

6.12. jn:parse-json

This function has the same semantics as fn:parse-xml(), except that it parses the string as JSON (not XML), and returns a sequence of objects or arrays rather than an XML document.
jn:parse-json($arg as xs:string?, $options as object()) as json-item()*
jn:parse-json($arg as xs:string?) as json-item()*
If $options("jsoniq-multiple-top-level-items") evaluates to the empty sequence, or the second parameter is not specified, it is considered to be true.
If $options("jsoniq-multiple-top-level-items") is not of type xs:boolean, then jerr:JNTY0020 is raised..
If $options("jsoniq-multiple-top-level-items") is true, then jn:parse-json recognizes and parses sequences of objects and arrays, with no separation other than whitespaces.
If parsing is not successful, then jerr:JNDY0021 is raised. Parsing is considered in particular to be non-successful if $options("jsoniq-multiple-top-level-items") is false and there is extra content after parsing a single abject or array.
Example 6.8. Parsing JSON items.
parse-json("{"foo" : "bar"} {"bar" : "foo"} [ 1, 2, 3 ]")
Result:
{ "foo" : "bar" }
{ "bar" : "foo" }
[ 1, 2, 3 ]