Skip to main content
Version: Streamsheets 3.0

JSON.TO.XML

Premium

Converts given JSON object into an XML text.

Syntax

=JSON.TO.XML(JSON, [XMLHeader])

Arguments

NameTypeDescription
JSONJSONA JSON object to convert.
XMLHeader (optional)BooleanProvide a custom header text or specify TRUE to add a standard XML header or FALSE to add no header.

Default value: TRUE

Return

TypeDescription
String or ErrorA text representing XML or an error value.

Examples

AB
1{"name": "foo", "age": 42}
2{"Customer id='1234' version='1.2'": { "name": "John" }}
3{"Customer": { "<!--": "a comment inside", "name": "John" }}
4{"Customers": { "Customer": [ { "name": "John" }, { "name": "Doe" } ]}
5{"name": "John" }<?xml version="1.0" ?>
FormulaResultComment
=JSON.TO.XML(JSON(A1))
<?xml version="1.0" encoding="utf-8"?>
<name>foo</name>
<age>42</age>
Create an XML from a simple JSON. JSON keys are used as element tags and their values as element text. A standard xml header is added.
=JSON.TO.XML(JSON(A2), FALSE)
<Customer id="1234" version="1.2">
<name>John</name>
</Customer>
Create an XML with tag attributes (Note: currently only keys with object/array values can have attributes): Attributes are simply listed within the JSON key.
=JSON.TO.XML(JSON(A3), FALSE)
<Customer>
<!--a comment inside-->
<name>John</name>
</Customer>
Create an XML with comments
=JSON.TO.XML(JSON(A4), FALSE)
<Customers>
<Customer>
<name>John</name>
</Customer>
<Customer>
<name>Doe</name>
</Customer>
</Customers>
Create an XML with list elements. All objects inside list must be under same JSON key.
=JSON.TO.XML(JSON(A5), B5)
<?xml version="1.0" ?>
<name>John</name>
Create an XML with custom XML header. A custom header is simply added without any further validation.