This document is also available in these non-normative formats: XML.
Copyright © 2000 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and document use rules apply.
This document defines methods of serializing an instance of the data model defined in [XDM 4.0] into a sequence of octets, conforming to a variety of formats including XML, HTML, and JSON. Serialization is designed to be a component that can be used either on its own, or invoked from languages such as [XSLT 4.0], [XPath 4.0] or [XQuery 4.0].
This section describes the status of this document at the time of its publication. Other documents may supersede this document.
This document is a working draft developed and maintained by a W3C Community Group, the XQuery and XSLT Extensions Community Group unofficially known as QT4CG (where "QT" denotes Query and Transformation). This draft is work in progress and should not be considered either stable or complete. Standard W3C copyright and patent conditions apply.
The community group welcomes comments on the specification. Comments are best submitted as issues on the group's GitHub repository.
The community group maintains two extensive test suites, one oriented to XQuery and XPath, the other to XSLT. These can be found at qt4tests and xslt40-test respectively. New tests, or suggestions for correcting existing tests, are welcome. The test suites include extensive metadata describing the conditions for applicability of each test case as well as the expected results. They do not include any test drivers for executing the tests: each implementation is expected to provide its own test driver.
The publications of this community group are dedicated to our co-chair, Michael Sperberg-McQueen (1954–2024).
Changes in 4.0 (next | previous)
Added the escape-solidus parameter for JSON serialization. [Issue 530 PR 534 6 June 2023]
Added the json-lines parameter for JSON serialization. [Issue 1471 15 October 2024]
The serialization of maps retains the order of entries. [Issue 1651 PR 1703 14 January 2025]
A JNode is replaced by its ·content· property. [Issue 2025 PR 2031 29 May 2025]
JSON canonicalization is supported by the ·canonical· property. [Issue 938 PR TODO 20 October 2025]
The JSON output method now produces fallback representation of NaN and infinity, rather than reporting an error for such values. [Issue 641 PR 2387 16 January 2026]
The JSON output method serializes the input tree using the JSON syntax defined in [RFC 7159], or (if the json-lines parameter is set to true) the json-lines syntax defined at [JSON Lines]. Sequence normalization is not performed for this output method. The effect of the json-lines parameter is explained at 9.2 JSON Lines.
If json-lines is set to false, then:
If the input value is an empty sequence, it is serialized as the string null.
If the input value is a single item, it is serialized as described below.
If the input value is a sequence containing two or more items, a serialization error results [err:SERE0023].
This appendix lists changes made in version 4.0 of this specification.
If a section of this specification has been updated since version 3.1, an overview of the changes is provided, along with links to navigate to the next or previous change.
See 1 Introduction
Sections with significant changes are marked with a ✭ symbol in the table of contents.
See 1 Introduction
PR 2114 2226
A JNode is represented as jnode(K: V) where K is its ·selector· property and V is its ·content· property.
The JSON output method now produces fallback representation of NaN and infinity, rather than reporting an error for such values.
PR TODO
Added the canonical parameter for XML, XHTML, and JSON serialization.
See 3 Serialization Parameters
JSON canonicalization is supported by the ·canonical· property.
The output of QNames reflects the new syntax for QName literals.
The term atomic value has been replaced by atomic item.
See 1.1 Terminology
Added the json-lines parameter for JSON serialization.
PR 342
In the HTML and XHTML output methods, the rules for adding and replacing meta elements have been revised to take account of the new HTML5 syntax, for example <meta charset="utf-8">.
PR 534
Added the escape-solidus parameter for JSON serialization.
See 3 Serialization Parameters
See 10.1 The Influence of Serialization Parameters upon the Adaptive Output Method
PR 1703
The serialization of maps retains the order of entries.
PR 1977
The default HTML version is now 5. This may result in changes to the serialized output in cases where no explicit HTML version is requested.
PR 2031
A JNode is replaced by its ·content· property.
PR 2387
The JSON output method now produces fallback representation of NaN and infinity, rather than reporting an error for such values.