org.basex.query.util.json
Class JsonCGConverter

java.lang.Object
  extended by org.basex.query.util.json.JsonConverter
      extended by org.basex.query.util.JsonXMLConverter
          extended by org.basex.query.util.json.JsonCGConverter

public final class JsonCGConverter
extends JsonXMLConverter

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 (<_>...</_>).
    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 whitespaces.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen, Leo Woerteler

Field Summary
 
Fields inherited from class org.basex.query.util.json.JsonConverter
COMPACT, info, JSONML, MAPS
 
Constructor Summary
JsonCGConverter(JsonParser.Spec sp, boolean unesc, InputInfo ii)
          Constructor.
 
Method Summary
 ANode convert(java.lang.String in)
          Converts the given JSON string into an XQuery value.
 
Methods inherited from class org.basex.query.util.json.JsonConverter
newInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonCGConverter

public JsonCGConverter(JsonParser.Spec sp,
                       boolean unesc,
                       InputInfo ii)
Constructor.

Parameters:
sp - JSON spec to use
unesc - unescape flag
ii - input info
Method Detail

convert

public ANode convert(java.lang.String in)
              throws QueryException
Description copied from class: JsonConverter
Converts the given JSON string into an XQuery value.

Specified by:
convert in class JsonXMLConverter
Parameters:
in - the JSON string
Returns:
the result
Throws:
QueryException - parse exception