|
|
|
|
|
- Properties specific to JSONXMLConverter variables
- JSON to XML and XML to JSON conversion standard
- Default conversion standard
- Special conversion cases
- WLanguage functions that use the JSONXMLConverter type
JSONXMLConverter (Variable type) In french: JSONXMLConvertisseur
The JSONXMLConverter type is used to define all the advanced characteristics of the conversion of an XML object to JSON (or conversely) via XMLToJSON and JSONToXML). You can define and change the characteristics of this conversion using different WLanguage properties. Note: For more details on the declaration of this type of variable and the use of WLanguage properties, see Declaring a variable. let json = StringToJSON("
{ "name": "TestName"
,"id": 2
,"vrai": true
,"list": [5,5,6,2,47]
}
")
let converter is JSONXMLConverter
converter.ArrayConversionWithRoot = False
converter.FullConversion = True
let xml = JSONToXML(json, converter)
Trace(xml..XMLSource)
Trace(XMLToJSON(xml, converter))
Properties Properties specific to JSONXMLConverter variables The following properties can be used to handle a converter: | | | Property name | Type used | Effect |
---|
ConversionTableWithRacine | Boolean | - True (default) to convert JSON arrays to XML using the name of the JSON element as root name,
- False otherwise.
| ElementName | Character string | Element names for rooted arrays. | EmptyBaliseRepresentation | Boolean | - True (default value) if the empty tag is represented by NULL,
- False otherwise.
| FullConversion | Boolean | - True (default) if the conversion must include attributes and namespaces,
- False to perform a simple conversion (ignoring attributes and namespaces).
| NomRacineXML | Character string | XML root name. By default, this property is set to "root". | PrefixAttribute | Character string | Prefix of XML attributes in JSON. By default, this property is set to "@". | PrefixCDATA | Character string | Key for escaping an XML section. By default, this property is set to "CDATA". | PrefixNamespaceDeclared | Character string | Prefix for declared namespaces. By default, this property is set to "%". | PrefixNamespaceNode | Character string | Prefix for the node namespace. By default, this property is set to "$". | PrefixText | Character string | Prefix of the text of XML text nodes in JSON. By default, this property is set to "#text". | TypingJSON | Boolean | - True (default value) if types are deducted when converting to JSON,
- False otherwise.
|
Remarks JSON to XML and XML to JSON conversion standard There are no specific standards for either type of conversion. However, there are two methods to define conversion operations: - Forcing a standard the during conversion (using the default values of the JSONXMLConverter variable).
- Using a custom conversion standard with a variable of type JSONXMLConverter to describe the conversion rules.
Default conversion standard XML to JSON - XML tag: "" + tag name followed by a JSON object.
- Empty tag: null JSON value.
- XML attribute: "@" + attribute name in JSON member of the object representing the tag.
- Text node: simple key/value pair if there are no attributes, "#text" if the node is a JSON object.
- Escape sections: "CDATA" with JSON string value.
JSON to XML - Empty object: empty tag if object is named.
- Empty list: empty tag if the array is named.
- Value: text node.
Special conversion cases JSON - XML conversion is not a common and lossless conversion, since the two languages have different syntax and data. Any conversion will require multiple adaptations to keep the data while limiting losses from the original document. The following is a list of the various conflict points and ambiguities that can occur during a conversion, as well as suggested solutions that allow for a reverse conversion (if possible) without compromising object data. XML to JSON - XML attribute JSON syntax doesn't have attributes for key-value pairs. To keep the notion of attributes, one solution is to prefix them in the JSON content and place them as object members.
- Namespace JSON syntax does not have a namespace for keys. A simple solution is to interpret them as standard names and attributes.
- Empty tag: JSON syntax doesn't allow for keys without any value. Two possibilities are available: to represent them by the null value or by an empty object (in the case of an empty tag with attributes, the only possible representation is the pseudo-empty object, containing only the tag's attributes).
- Text node Text nodes can be represented as key-value pairs, but the presence of attributes can lead to the creation of an object as the value of the key representing the node. In order to keep a reference to the textual value of the node, one solution consists in creating an internal couple containing the text of the node.
- Node list: XML lists are easily transposed into JSON, but since JSON keys cannot be duplicated, there may be a loss of child node scheduling in some cases.
- Escape sections Escape sections: JSON doesn't have the notion of escape sections, but it is possible to store them as special fields in the target JSON content, like text nodes.
- Comments JSON has no notion of comments. The solution is to simply not copy them to the target JSON content, since they are optional.
JSON to XML - Value type XML documents have no notion of type. These types will be lost; otherwise, the original types must be stored in the generated XML document.
- Empty list: XML doesn't technically have empty lists. Considering them as empty tags implies a risk of conflict with empty and/or null objects.
- Empty / null object The empty XML tag can represent these JSON notions, but to enable Reverse conversion, you need to choose one of the two representations.
WLanguage functions that use the JSONXMLConverter type
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|