Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Appendix A Advanced Topics : JSON Render Related Properties

JSON Render Related Properties
When rendering XML data to JSON data, you can implement the following functions by configuring the JSON Render related properties:
Checking Empty Elements for JSON Render
If the XSD schema type is used when rendering the XML data to JSON data, by default, the XML elements that are not defined in XML but defined in XSD are ignored during the conversion.
However, such XML elements can be rendered to an empty JSON array or an empty JSON object accordingly by setting up a parameter, when the XSD schema type is used.
To preserve the empty XML elements when rendering JSON with the XSD schema type:
1.
Navigate to the TIBCO_HOME\designer\version_number\bin directory.
2.
Open the designer.tra file.
3.
Add the com.tibco.plugin.restjson.xml2json.checkEmptyElement property in the file and set its value to true.
4.
If such elements have a namespace defined, after conversion, the namespace with emp followed after the prefix xmlns is added to the JSON objects.
Example
For example, the input data is shown as follows:
<home>
  <address>
    <address2>homeAddress</address2>
    <city>cityName</city>
    <state>StateName</state>
  </address>
</home>
After you set the property value to true, the empty XML elements that are not defined in XML but defined in XSD are rendered into empty JSON array or empty JSON objects when the XSD schema type is used. The output is displayed as follows:
{
  "home":{
    "address":{
      "address1":[
      ],
      "address2":"homeAddress",
      "city":"cityName",
      "state":"StateName"
    }
  }
}
If you set the property value to false or do not add the property, the output is displayed as follows:
{
  "home":{
    "address":{
      "address2":"homeAddress",
      "city":"cityName",
      "state":"StateName"
    }
  }
}
Ignoring Namespace
You can configure the com.tibco.plugin.restjson.xml2json.namespaceIgnored property to ignore the namespace and prefix information when converting XML to JSON. The default value is false, indicating that the namespace information is considered when rendering JSON files. The value true indicates that the namespace information is ignored.
This property is applicable for the Generic and XSD schema types.
To ignore the namespace information:
1.
Navigate to the TIBCO_HOME\designer\version_number\bin directory.
2.
Open the designer.tra file.
3.
Add the com.tibco.plugin.restjson.xml2json.namespaceIgnored property in the file and set its value to true.
4.
Example
For example, the input data is shown as follows:
<root_ns xmlns = "http://NamespaceTest.com/Parent">
  <person_id>001a</person_id>
</root_ns>
After you set the property value to true, the namespace is ignored. The output data is displayed as follows:
{
  "root_ns":{
    "person_id":{
      "$":"001a"
    }
  }
}
If you do not add this property, or set this property value to false, the output is displayed as follows:
{
  "root_ns":{
    "@xmlns":"http://NamespaceTest.com/Parent",
    "person_id":{
      "$":"001a"
    }
  }
}
Escaping Forward Slash
You can configure the com.tibco.plugin.restjson.xml2json.forwardSlashEscaping property to escape the forward slash when rendering JSON files. The default value is false, indicating that the forward slash is kept when rendering JSON files. The value true indicates that the forward slash is escaped: "/" is converted to "\/".
This property is applicable for the Generic and XSD schema types.
To escape the forward slash:
1.
Navigate to the TIBCO_HOME\designer\version_number\bin directory.
2.
Open the designer.tra file.
3.
Add the com.tibco.plugin.restjson.xml2json.forwardSlashEscaping property in the file and set its value to true.
4.
Example
For example, the input data is shown as follows:
<Phone>
  <telephone xmlns =   "http://NamespaceTest.com/test">8161000</telephone>
</Phone>
After you set the property value to true, the forward slash is escaped. The output data is displayed as follows:
{
  "Phone":{
    "telephone":{
      "@xmlns":"http:\/\/NamespaceTest.com\/test",
      "$":"8161000"
    }
  }
}
If you do not add this property, or set this property value to false, the output is displayed as follows:
{
  "Phone":{
    "telephone":{
      "@xmlns":"http://NamespaceTest.com/test",
      "$":"8161000"
    }
  }
}
Formatting the Output String
You can configure the com.tibco.plugin.restjson.json.prettyPrint property to decide whether you want to format the output string. The default value is true, indicating that you want to format the output string.
This property is applicable for the Generic and XSD schema types.
To format the output string:
1.
Navigate to the TIBCO_HOME\designer\version_number\bin directory.
2.
Open the designer.tra file.
3.
Add the com.tibco.plugin.restjson.json.prettyPrint property in the file and set its value to true.
4.
Example
For example, the input data is shown as follows:
<root_attr attr_default="newDefault" attr_fixed="attr_fixed_value">
  <people_info>
    <people_address attr_optional="attr_required_optional" attr_required="attr_required_value">
      <street>XD</street>
      <city>BJ</city>
      <state>BJ</state>
      <country>China</country>
    </people_address>
    <children_number>35</children_number>
  </people_info>
  <product prodid="12">tv</product>
  <shoesize color="black">39</shoesize>
</root_attr>
If you set the property value to true or do not add this property, the output data is displayed as follows:
{
  "root_attr": {
    "@attr_default": "newDefault",
    "@attr_fixed": "attr_fixed_value",
    "people_info": {
      "people_address": {
            "@attr_optional": "attr_required_optional",
            "@attr_required": "attr_required_value",
            "street": {
              "$": "XD"
            },
            "city": {
              "$": "BJ"
            },
            "state": {
              "$": "BJ"
            },
            "country": {
              "$": "China"
            }
      },
      "children_number": {
            "$": 35
      }
    },
    "product": {
      "@prodid": 12,
      "$": "tv"
    },
    "shoesize": {
      "@color": "black",
      "$": 39
    }
  }
}
If you set this property value to false, the output is displayed as follows:
{"root_attr":{"@attr_default":"newDefault","@attr_fixed":"attr_fixed_value","people_info":{"people_address":
{"@attr_optional":"attr_required_optional","@attr_required":"attr_required_value","street":{"$":"XD"},"city":{"$":"BJ"},"state":{"$":"BJ"},"country":
{"$":"China"}},"children_number":{"$":35}},"product":{"@prodid":12,"$":"tv"},"shoesize":{"@color":"black","$":39}}}

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved