JSON.TO.XML
Premium
Converts given JSON object into an XML text.
Syntax
=JSON.TO.XML(JSON, [XMLHeader])
Arguments
Name | Type | Description |
---|---|---|
JSON | JSON | A JSON object to convert. |
XMLHeader (optional) | Boolean | Provide a custom header text or specify TRUE to add a standard XML header or FALSE to add no header. Default value: TRUE |
Return
Type | Description |
---|---|
String or Error | A text representing XML or an error value. |
Examples
A | B | |
---|---|---|
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" ?> |
Formula | Result | Comment |
---|---|---|
| <?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. |
| <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. |
| <Customer> <!--a comment inside--> <name>John</name> </Customer> | Create an XML with comments |
| <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. |
| <?xml version="1.0" ?> <name>John</name> | Create an XML with custom XML header. A custom header is simply added without any further validation. |