JSON and XML are both widely used for data interchange on the Internet. In many applications, JSON is replacing XML in Web Service APIs and data feeds; other applications support both formats. XML adds significant overhead for namespaces, whitespace handling, the oddities of XML Schema, and other things that are simply not needed in many data-oriented applications that require no more than simple serialization of program structures. On the other hand, many applications do need these features, and the ability to use document data together with traditional program data is important.
JSONiq is a small and simple set of extensions to XQuery that add support for JSON. For applications that need only JSON, we have defined a profile called XQ-- that removes all support for XML constructors, path expressions, user defined functions, and some other features considered unnecessary for most JSON queries. Syntax diagrams for XQ-- are available at
http://jsoniq.org/grammars/xq--/ui.xhtml.
For applications that need to process XML together with JSON, we have defined a profile called XQ++ that adds these extensions to the full XQuery language. Syntax diagrams for XQ++ are available at
http://jsoniq.org/grammars/xq++/ui.xhtml.
JSONiq consists of the following extensions to XQuery:
Extensions to the XQuery Data Model (XDM) to support JSON.
Support for JSON's datatypes, with a mapping to equivalent XML Schema types.
Navigation for JSON Objects and JSON Arrays.
Constructors for JSON Objects, Pairs, and JSON Arrays, using the same syntax as JSON.
Update primitives against JSON items as well as updating expressions which produce them.
New item types, which extend sequence type matching to allow the type of JSONiq datatypes to be specified in function parameters, return types, and other expressions that specify XQuery types.
JSONiq is designed to seamlessly integrate in XQuery's full composability paradigm. In particular, JSON constructors can appear in any XQuery expression, and any XQuery expression can appear in a JSON constructor.
The namespace http://jsoniq.org/functions
is used for functions defined by this specification. This namespace is exposed to the user and is bound by default to the prefix jn
. For instance, the function name jn:json-doc()
is in this namespace.
The namespace http://jsoniq.org/types
is used for types defined by this specification. This namespace is exposed to the user and is bound by default to the prefix jn
. For instance, the type name js:null
is in this namespace.
The namespace http://jsoniq.org/function-library
is used for library functions defined by this specification. This namespace is exposed to the user, however no prefix is predeclared for this namespace. For convenience, this document uses the prefix libjn:
for names in this namespace. For instance, the function name libjn:accumulate
is in this namespace.
The namespace http://jsoniq.org/errors
is used for the names of errors defined by this specification. This namespace is exposed to the user, however no prefix is predeclared for this namespace. For convenience, this document uses the prefix jerr:
for names in this namespace. For instance, the error name jerr:JQTY0001
is in this namespace.
The namespace http://jsoniq.org/updates
is used for the names of update primitives defined by this specification. This namespace is not exposed to the user. For convenience, this document uses the prefix jupd:
for names in this namespace. For instance, the update primitive jupd:delete-from-object
is in this namespace.
Accessors used in JSONiq Data Model use the jdm:
prefix. These functions are not exposed to the user and are for explanatory purposes of the data model within this document only. The jdm:
prefix is not associated with a namespace.