Product SiteDocumentation Site

Chapter 3. JSONiq Data Model

3.1. Simple Datatypes
3.2. JSON Items
3.3. Objects
3.4. Arrays
3.5. ItemTypes for JSONiq Items
JSONiq is based on the XQuery Data Model, adding support for JSON nulls, objects and arrays. [1]
To support nulls, JSONiq adds the following atomic datatype:
To support JSON objects and arrays, JSONiq adds the following new items:
As well as the generic term (associated with an item type):

3.1. Simple Datatypes

JSON's simple values can have any of the following datatypes, which are supported as primitives in JSONiq.
  • string
  • number
  • boolean (true, false)
  • null
JSONiq represents a JSON string (a sequence of Unicode characters) as an xs:string. However, JSON supports strings (after resolving escaped characters) with characters of arbitrary unicode codepoints, whereas XML 1.0 and XML 1.1 only support a subset of these. It is implementation-defined if unicode characters outside of XML 1.0 or XML 1.1 are supported. Implementations which support XML 1.1 (which only excludes the null character) are encouraged to add support for the null character to provide full-fledged JSON support.
JSONiq represents the JSON simple values 'true' and 'false' as xs:boolean values.
JSONiq adds one new data type: js:null, derived from xs:anyAtomicType. js:null has a singleton value space containing the value null [2]. The lexical representation of an instance of js:null is the string "null".
JSON defines number as follows:
A number can be represented as integer, real, or floating point. JSON does not support octal or hex because it is minimal. It does not have values for NaN or Infinity because it does not want to be tied to any particular internal representation.
JSONiq uses XQuery's lexical representation of numbers to distinguish integer, real, and floating point numbers [3]:
NumericLiteral ::= IntegerLiteral | DecimalLiteral | DoubleLiteral
If a numeric literal has no "." character and no e or E character, it has the atomic type xs:integer; if it has a "." character but no e or E character it has type xs:decimal; if it has an e or E character it has type xs:double.
Number literals are mapped to atomic values according to the XML Schema specification.

[1] In the XQ-- subset of JSONiq, we will define a simpler data model that omits much of the XQuery Data Model.
[2] (Because the typed value of all js:null instances is the same, nulls are always equal to each other for the purpose of value comparisons).
[3] The result of a JSONiq query may contain values such as NaN or Infinity, which cannot be serialized as JSON. These values have type xs:double, and are either rejected or treated in a special way during the JSON Serialization process.
ECMAScript also has has Infinity and NaN, and takes a similar approach.