Package org.basex.io.parse.json
Class JsonDirectConverter
java.lang.Object
org.basex.io.parse.json.JsonConverter
org.basex.io.parse.json.JsonDirectConverter
This class converts a JSON document to XML. The converted XML document is both well readable and lossless, i.e., the converted document can be serialized back to the original JSON representation.
The specified JSON input is first transformed into a tree representation and then converted to an XML document, according to the following rules:
- The resulting document has a
<json/>root node. - Names (keys) of objects are represented as elements:
- Empty names are represented by a single underscore
(
<_>...</_>). - Underscore characters are rewritten to two underscores (
__). - A character that cannot be represented as NCName character is rewritten to an underscore and its four-digit Unicode.
- Empty names are represented by a single underscore
(
- As arrays have no names,
<value/>is used as element name. - JSON values are represented as text nodes.
- The types of values are represented in attributes:
- The value types number, boolean, null,
object and array are represented by a
typeattribute. - The string type is omitted, as it is treated as default type.
- If a name has the same type throughout the document, the
typeattribute will be omitted. Instead, the name will be listed in additional, type-specific attributes in the root node. The attributes are named by their type in the plural (numbers, booleans, nulls, objects and arrays), and the attribute value contains all names with that type, separated by whitespaces.
- The value types number, boolean, null,
object and array are represented by a
- Author:
- BaseX Team 2005-21, BSD License, Christian Gruen, Leo Woerteler
-
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanLit(byte[] value) voidnullLit()voidnumberLit(byte[] value) voidstringLit(byte[] value) Methods inherited from class org.basex.io.parse.json.JsonConverter
convert, convert, fallback, get
-
Method Details
-
numberLit
public void numberLit(byte[] value) -
stringLit
public void stringLit(byte[] value) -
nullLit
public void nullLit() -
booleanLit
public void booleanLit(byte[] value)
-