Changes

Jump to navigation Jump to search
496 bytes removed ,  13:06, 2 July 2020
This [[Module Library|XQuery Module]] contains functions to parse and serialize JSON data [httphttps://www.json.org/ JSON (JavaScript Object Notation)] is a popular data exchange format for applications written in JavaScript. As there are notable differences between JSON and XML, or XQuery data types, no mapping exists that guarantees a lossless, bidirectional conversion between JSON and XML. For this reason, we offer various mappings, all of which are suited to different use cases.
=Conventions=
The {{Code|direct}} conversion format allows a lossless conversion from JSON to XML and back. The transformation is based on the following rules:
* The resulting document has a {{Code|<json>}} root node. * Object pairs are represented via elements. The name of a pair is rewritten to an element name:** Empty names are represented by a single underscore ({{Code|_}}). Existing underscores are rewritten to two underscores ({{Code|__}})encoded, and characters that are not valid as described in element names are rewritten to an underscore and the character’s four-digit Unicode.** If the {{Code[[Conversion Module#Keys|lax}} option is set to {{Code|true}}Conversion Module]], invalid characters are simply replaced with underscores or (when invalid and used as first character of an element name) prefixed with an underscore. The resulting names are better readable, but cannot always be converted back to their original form.* Array entries are also represented via elements. , with {{Code|_}} is used as element name.
* Object and array values are stored in text nodes.
* The types of values are represented via {{Code|type}} attributes:
The {{Code|attributes}} format is lossless, too. The transformation based on the following rules:
* The resulting document has a {{Code|<json>}} root node. * Object pairs are represented via {{Code|<pair>}} elements. The name of a pair is stored in a {{Code|name}} attribute.* Array entries are represented via {{Code|<item>}} elements.
* Object and array values are stored in text nodes.
* The types of values are represented via {{Code|type}} attributes:
|- valign="top"
| {{Code|liberal}}
| Determines if minor deviations from [httphttps://www.rfc-editor.org/rfc/rfc7159.txt RFC 7159] will be ignored.
| {{Code|yes}}, {{Code|no}}
| {{Code|no}}
|}
==json:serializedoc== {{Mark|Introduced with BaseX 9.4:}}
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|json:serializedoc|$input uri as xs:string|item()?|xs:string}}<br/>{{Func|json:serializedoc|$input uri as item()?xs:string, $options as map(*)?|xs:stringitem()?}}<br />
|-
| '''Summary'''
|Serializes Fetches the specified {{Code|$input}} as JSON, using document referred to by the specified given {{Code|$optionsuri}}, and returns the result as string:* The input is expected to conform converts it to the results that are created by [[#json:parse|json:parse()]].* Non-conforming items will be serialized as specified in the [[an XQuery 3.1#JSON Serialization|json output method]] of the official recommendationvalue.Values can also be serialized as JSON with the standard [[Serialization]] feature of XQuery:* The parameter {{Code|method$options}} needs to argument can be set used to {{Code|json}}, and* control the options presented in this article need to be assigned to way the {{Code|json}} parameterinput is converted.
|-
| '''Errors'''
|{{Error|serializeparse|#Errors}} the specified node input cannot be serialized parsed as JSON document.<br/>{{Error|options|#Errors}} the specified options are conflicting.
|}
==json:docserialize== {{Mark|Introduced with BaseX 9.4:}}
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|json:docserialize|$uri input as xs:string|item()?|xs:string}}<br />{{Func|json:docserialize|$uri input as xs:stringitem()?, $options as map(*)?|item()?xs:string}}<br />
|-
| '''Summary'''
|Fetches Serializes the specified {{Code|$input}} as JSON document referred to by , using the given specified {{Code|$urioptions}} , and converts it returns the result as string:* The input is expected to conform to an the results that are created by [[#json:parse|json:parse()]].* Non-conforming items will be serialized as specified in the [[XQuery value3.1#JSON Serialization|json output method]] of the official recommendation. Values can also be serialized as JSON with the standard [[Serialization]] feature of XQuery:* The parameter {{Code|$optionsmethod}} argument can needs to be used set to control {{Code|json}}, and* the way options presented in this article need to be assigned to the input is converted{{Code|json}} parameter.
|-
| '''Errors'''
|{{Error|parseserialize|#Errors}} the specified input node cannot be parsed serialized as JSON document.<br/>{{Error|options|#Errors}} the specified options are conflicting.
|}
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu