org.basex.query.util.json
Class JsonCGConverter
java.lang.Object
org.basex.query.util.json.JsonConverter
org.basex.query.util.JsonXMLConverter
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:
- 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.
- 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
type
attribute.
- The string type is omitted, as it is treated as default type.
- 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
Method Summary |
ANode |
convert(java.lang.String in)
Converts the given JSON string into an XQuery value. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JsonCGConverter
public JsonCGConverter(JsonParser.Spec sp,
boolean unesc,
InputInfo ii)
- Constructor.
- Parameters:
sp
- JSON spec to useunesc
- unescape flagii
- input info
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