You can use the data mashup builder to convert JSON source into XML so that you can manipulate a feed using the other operators. Likewise, you can convert XML into JSON in the Publish operator. Converting between the JSON and XML formats has specific rules and limitations.

Using JSON format in the Source Operator

When you convert the JSON source into XML, the following changes occur:

A top-level root element called <root> is added to the XML document.

Each JSON name-value pair is converted into an XML element.

If the JSON name contains a character that is not valid XML, the character is replaced by the underscore character (_).

A JSON array is converted to XML repeating elements with the parent name.

Following is an example of converting JSON source to XML. The JSON source has a list of park objects and the "zip$code" name has an invalid XML character ("$"):

{

"park":

[

{

"address": "Fort Mason",

"name": "Alcatraz Island",

"zip\$code": "94123",

"state": "CA",

"city": "San Francisco"

},

{

"address": "PO Box 579",

"name": "Death Valley",

"zip\$code": "92328",

"state": "CA",

"city": "Death Valley"

}

]

}

When converted to XML, the code has a root node named <root>, "park" becomes the feed-level repeating element <park>, and the "zip$code" name is converted to the <zip_code> element:

<?xml version="1.0"?>

<root>

<park>

<address>Fort Mason</address>

<name>Alcatraz Island</name>

<zip_code>94123</zip_code>

<state>CA</state>

<city>San Francisco</city>

</park>

<park>

<address>PO Box 579</address>

<name>Death Valley</name>

<zip_code>92328</zip_code>

<state>CA</state>

<city>Death Valley</city>

</park>

</root>

Note: Depending on the structure of the feed, you can select a different top-level repeating element in the Advanced tab of the Source operator.

JSON unnamed lists of objects are converted into <item> elements. For example, given a JSON feed that is an unnamed list of objects, such as the following:

[

{

"address": "Fort Mason",

"name": "Alcatraz Island",

"zip\$code": "94123",

"state": "CA",

"city": "San Francisco"

},

{

"address": "PO Box 579",

"name": "Death Valley",

"zip\$code": "92328",

"state": "CA",

"city": "Death Valley"

}

]

When converted to XML, the feed-level repeating element is set to <item>:

<?xml version="1.0"?>

<root>

<item>

<address>Fort Mason</address>

<name>Alcatraz Island</name>

<zip_code>94123</zip_code>

<state>CA</state>

<city>San Francisco</city>

</item>

<item>

<address>PO Box 579</address>

<name>Death Valley</name>

<zip_code>92328</zip_code>

<state>CA</state>

<city>Death Valley</city>

</item>

</root>

After loading this JSON code in the Source operator, you can set the repeating element to /root/item in the Advanced tab.

Troubleshooting JSON source in the Source Operator

Do not use JavaScript in the JSON feed URL.

If the source does not return results:

Check the code by loading the JSON URL in the Firefox browser.

Verify that the feed is valid.

Using JSON format in the Publish Operator

The Publish operator supports two JSON output formats:

JSON Object: The JSON Object is an unordered collection of name-value pairs. When you select the JSON object feed type in the Publish operator, you must enter the repeating element name. The feed is enclosed within a JSON object with the JSON name set to the repeating element.

JSON Array: The JSON array is an ordered list of values. No additional fields are required in the Publish operator for a JSON Array feed type.

When you convert XML into JSON, the following changes occur:

The output order is not retained, except for the repeating elements.

Empty elements are output with a value of true, instead of as null.

If an XML element has both attributes and a value, the value is output in the JSON object with the name "content".