JSON.TO.XML
This is a premium feature.
Converts given JSON object into an XML text.
Syntax
=JSON.TO.XML(JSON, [XMLHeader])
Arguments
Name | Description |
---|---|
JSON | A JSON object to convert. |
XMLHeader (optional) | Provide a custom header text or specify TRUE to add a standard XML header or FALSE to add no header. Defaults to TRUE. |
Return
A text representing XML or an error value.
Examples
Formula | Result | Comment |
---|---|---|
| <?xml version="1.0" encoding="utf-8"?> <name>foo</name> <age>42</age> | Create an XML from a simple JSON: A1: {"name": "foo", "age": 42 } JSON keys are used as element tags and their values as element text. A standard xml header is added. |
| <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): A1: { "Customer id='1234' version='1.2'": { "name": "John" } } Attributes are simply listed within the JSON key. |
| <Customer> <!--a comment inside--> <name>John</name> </Customer> | Create an XML with comments: A1: { "Customer": { "<!--": "a comment inside", "name": "John" } } ` Comments must have a <!-- JSON key |
| <Customers> <Customer> <name>John</name> </Customer> <Customer> <name>Doe</name> </Customer> </Customers> | Create an XML with list elements: A1: { "Customers": { "Customer": [ { "name": "John" }, { "name": "Doe" } ] } All objects inside list must be under same JSON key. |
| <?xml version="1.0" ?> <name>John</name> | Create an XML with custom XML header: A1: { "name": "John" }, B1: "<?xml version="1.0" ?> A custom header is simply added without any further validation. |