Skip to main content
Version: Streamsheets 2.4

JSON.TO.XML

star This is a Streamsheets Enterprise feature.

Converts given JSON object into an XML text.

Syntax

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

Arguments

NameDescription
JSONA JSON object to convert.
XMLHeaderOptional. Provide a custom header text or specify TRUE to add a standard XML header or FALSE to add no header. Defaults to TRUE.

Return Value

A text representing XML or an error value.

Examples

Create an XML from a simple JSON:

A1: {"name": "foo", "age": 42 }

FunctionResultComment
=JSON.TO.XML(JSON(A1))<?xml version="1.0" encoding="utf-8"?>
<name>foo</name>
<age>42</age>
JSON keys are used as element tags and their values as elment text. A standard xml header is added.

Create an XML with tag attributes (Note: currently only keys with object/array values can have attributes):

A1: { "Customer id='1234' version='1.2'": { "name": "John" } }

FunctionResultComment
=JSON.TO.XML(JSON(A1), FALSE)<Customer id="1234" version="1.2">
<name>John</name>
</Customer>
Attributes are simply listed within the JSON key.

Create an XML with comments:

A1: { "Customer": { "<!--": "a comment inside", "name": "John" } }

FunctionResultComment
=JSON.TO.XML(JSON(A1), FALSE)<Customer>
<!--a comment inside-->
<name>John</name>
</Customer>
Comments must have a <!-- JSON key

Create an XML with list elements:

A1: { "Customers": { "Customer": [ { "name": "John" }, { "name": "Doe" } ] }

FunctionResultComment
=JSON.TO.XML(JSON(A1), FALSE)<Customers>
<Customer>
<name>John</name>
</Customer>
<Customer>
<name>Doe</name>
</Customer>
</Customers>
All objects inside list must be under same JSON key.

Create an XML with custom XML header:

A1: { "name": "John" }, B1: "<?xml version="1.0" ?>

FunctionResultComment
=JSON.TO.XML(JSON(A1), B1)<?xml version="1.0" ?>
<name>John</name>
A custom header is simply added without any further validation.