Class JsonDirectConverter


  • public final class JsonDirectConverter
    extends JsonConverter

    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:

    1. The resulting document has a <json/> root node.
    2. Names (keys) of objects are represented as elements:
      1. Empty names are represented by a single underscore (&lt;_&gt;...&lt;/_&gt;).
      2. Underscore characters are rewritten to two underscores (__).
      3. A character that cannot be represented as NCName character is rewritten to an underscore and its four-digit Unicode.
    3. As arrays have no names, <value/> is used as element name.
    4. JSON values are represented as text nodes.
    5. The types of values are represented in attributes:
      1. The value types number, boolean, null, object and array are represented by a type attribute.
      2. The string type is omitted, as it is treated as default type.
      3. If a name has the same type throughout the document, the type attribute 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 whitespace.
    Author:
    BaseX Team 2005-24, BSD License, Christian Gruen, Leo Woerteler