Changes

Jump to navigation Jump to search
152 bytes added ,  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}}
| '''Summary'''
|Converts the JSON {{Code|$string}} to an XQuery value. If the input can be successfully parsed, it can be serialized back to the original JSON representation. The {{Code|$options}} argument can be used to control the way the input is converted.
|-
| '''Errors'''
|{{Error|parse|#Errors}} the specified input cannot be parsed as JSON document.<br/>{{Error|options|#Errors}} the specified options are conflicting.
|}
 
==json:doc==
 
{{Mark|Introduced with BaseX 9.4:}}
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|json:doc|$uri as xs:string|item()?}}<br />{{Func|json:doc|$uri as xs:string, $options as map(*)?|item()?}}<br />
|-
| '''Summary'''
|Fetches the JSON document referred to by the given {{Code|$uri}} and converts it to an XQuery value. The {{Code|$options}} argument can be used to control the way the input is converted.
|-
| '''Errors'''
=Changelog=
 
;Version 9.4
* Added: [[#json:doc|json:doc]]
; Version 9.1
Bureaucrats, editor, reviewer, Administrators
13,551

edits

Navigation menu