Product SiteDocumentation Site

Chapter 4. JSONiq types

4.1. Item types
4.1.1. Atomics
4.1.2. JSON items
4.1.3. The most general item type.
4.2. Sequence types
This section describes JSONiq types as well as the sequence type syntax.
JSONiq manipulates semi-structured data: in general, JSONiq allows you, but does not require you to specify types. So you have as much or as little type verification as you wish.
JSONiq is still strongly typed, so that you will be told if there is a type inconsistency or mismatch in your programs.
Whenever you do not specify the type of a variable or the type signature of a function, the most general type for any sequence of items, item*, is assumed.
Section Section 5.7, “Expressions dealing with types” introduces expressions which work with values of these types, as well as type operations (variable types, casts, ...).

4.1. Item types

4.1.1. Atomics

AtomicOrUnionType
Figure 4.1. AtomicOrUnionType

Atomic types are organized in a tree hierarchy.
JSONiq defines the following build-in types that have a direct relation with JSON:
  • string: the value space is all strings made of Unicode characters.
    All string literals build an atomic which matches string.
  • integer: the value space is that of all mathematical integral numbers (N), with an infinite range. This is a subtype of decimal, so that all integers also match the item type decimal.
    All integer literals build an atomic which matches integer.
  • decimal: the value space is that of all mathematical decimal numbers (D), with an infinite range.
    All decimal literals build an atomic which matches decimal.
  • double: the value space is that of all IEEE double-precision 64-bit floating point numbers.
    All double literals build an atomic which matches double.
  • boolean: the value space contains the booleans true and false.
    All boolean literals build an atomic which matches boolean.
  • null: the value space is a singleton and only contains null.
    All null literals build an atomic which matches null.
  • atomic: all atomic types.
    All literals build an atomic which matches atomic.
JSONiq also supports further atomic types, which were borrowed from XML Schema.
These datatypes are already used as a set of atomic datatypes by the other two semi-structured data formats of the Web: XML and RDF, as well as by the corresponding query languages: XQuery and SPARQL, so it is natural for a complete JSON data model to reuse them.
  • Further number types: long, int, short, byte, float.
  • Date or time types: date, dateTime, dateTimeStamp, gDay, gMonth, gMonthDay, gYear, gYearMonth, time.
  • Duration types: duration, dayTimeDuration, yearMonthDuration.
  • Binary types: base64Binary, hexBinary.
  • An URI type: anyURI.

4.1.2. JSON items

JSONItemTest
Figure 4.2. JSONItemTest

All objects match the item type object as well as json-item.
All arrays match the item type array as well as json-item.

4.1.3. The most general item type.

All items match the item type item.
ItemType
Figure 4.3. ItemType