# JSON to XML Converter

Convert JSON to well-formed XML with configurable root and array item names, attributes, text nodes, pretty printing, and an optional XML declaration.

## Run it

- **CLI:** `gizza tool json-to-xml '{"book":{"@id":"dune","title":"Dune","authors":["Frank Herbert"]}}'`
- **Web:** https://gizza.ai/tools/json-to-xml/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/json-to-xml/tool.json

## Inputs

- `json` — JSON _(field)_
- `root_element` — Root element _(field)_
- `array_item_element` — Array item element _(field)_
- `format` — Output style _(field)_
- `indent` — Indent spaces _(field)_
- `xml_declaration` — Add XML declaration _(field)_
- `attribute_prefix` — Attribute prefix _(field)_
- `text_key` — Text key _(field)_

## Output

- XML output (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `json` — JSON
- `root_element` — Root element
- `array_item_element` — Array item element
- `format` — Output style
- `indent` — Indent spaces
- `xml_declaration` — Add XML declaration
- `attribute_prefix` — Attribute prefix
- `text_key` — Text key

Example: `https://gizza.ai/tools/json-to-xml/?json=%7B%22book%22%3A%7B%22%40id%22%3A%22dune%22%2C%22title%22%3A%22Dune%22%2C%22authors%22%3A%5B%22Frank%20Herbert%22%5D%7D%7D&root_element=root&array_item_element=item&format=pretty&indent=2&xml_declaration=true&attribute_prefix=%40&text_key=%23text`

---

## About this tool

Convert a JSON document into well-formed XML without uploading data. Objects become nested elements, arrays use a configurable item element, scalar values become text, and `null` values become empty self-closing elements. Keys are sanitized into valid XML names so data with spaces or punctuation still produces parseable XML.

The default mapping treats object keys that start with `@` as attributes and `#text` as element text. For example, `{"book":{"@id":"dune","#text":"Dune"}}` becomes `<book id="dune">Dune</book>`. Change those conventions if you need to match another JSON/XML pipeline, or clear the attribute prefix to render every key as a child element.

Worked example:

Input JSON:

```json
{"book":{"@id":"dune","title":"Dune","authors":["Frank Herbert"]}}
```

With `root_element=catalog` and `array_item_element=author`, the XML is:

```xml
<catalog>
  <book id="dune">
    <title>Dune</title>
    <authors>
      <author>Frank Herbert</author>
    </authors>
  </book>
</catalog>
```

Limits and edge cases: this is a structural converter, not an XML schema validator. JSON has no native distinction between XML attributes, text nodes, comments, namespaces, processing instructions, and repeated sibling names, so those are controlled by simple naming conventions. Very large JSON documents can produce much larger XML; use compact mode when whitespace matters.

## FAQ

<details>
<summary>How are JSON arrays converted?</summary>

Each array value becomes a repeated child element using the array item element name. The default is `item`, so `["a","b"]` under a `tags` key becomes `<tags><item>a</item><item>b</item></tags>`. Change the item name to match your target schema, such as `row`, `entry`, or `author`.

</details>

<details>
<summary>Can I create XML attributes from JSON?</summary>

Yes. By default, scalar object keys starting with `@` become attributes on the parent element. For example, `{"user":{"@id":"42","name":"Ada"}}` renders `<user id="42"><name>Ada</name></user>`. Set a different attribute prefix if another convention is required, or set it empty to disable attribute handling.

</details>

<details>
<summary>What happens to invalid XML tag names?</summary>

Keys are sanitized instead of failing the whole conversion: unsupported characters become underscores, and names that start with a digit get a leading underscore. For example, `"1 bad!"` becomes `<_1_bad_>`. If you need exact tag names, rename those keys in the JSON before converting.

</details>

<details>
<summary>Does this preserve comments, namespaces, or an XML schema?</summary>

No. Plain JSON cannot represent XML comments, namespace declarations, processing instructions, or schema types without a custom convention. This tool focuses on deterministic JSON-to-element conversion with optional attributes and text content; validate the result against your schema afterward if one is required.

</details>

## Related tools

- [CSV ⇄ JSON Converter](https://gizza.ai/tools/csv-json-convert/): Convert CSV to JSON or JSON to CSV in your browser — auto-detects direction, infers types, handles quoted fields and custom delimiters. Free, no upload.
- [Outline to JSON](https://gizza.ai/tools/outline-to-json/): Turn an indented text outline into nested JSON in your browser — spaces or tabs, children-array or nested-object shape, pretty or minified. Free, private.
- [Text to JSON](https://gizza.ai/tools/text-to-json/): Paste INI, key=value / .env, logfmt, CSV, or /etc/passwd-style text and get clean JSON. Auto-detects the format, infers types, and runs entirely in your browser.
- [Amazon Order Analyzer](https://gizza.ai/tools/amazon-order-analyzer/): Paste an Amazon order-history CSV export to summarize total spend by month, top items, and category breakdowns. Browser-only, private, with Markdown or JSON output.
- [Avro to JSON Converter](https://gizza.ai/tools/avro-to-json/): Decode Apache Avro Object Container Files (.avro / OCF) to JSON, NDJSON, or the embedded schema — no .avsc needed, free and private in your browser.
