JSON to XML with Attributes — What Our Browser Converter Actually Does
- This browser converter outputs element-only XML — every JSON value becomes an element, never an attribute.
- Two ways to get attribute output: a short XSLT post-process, or hand-edit for 2-3 fields.
- For production pipelines, Jackson XmlMapper (Java) or xmltodict (Python) give full attribute control.
Table of Contents
Our browser JSON to XML converter outputs element-only XML — every JSON value becomes a child element, never an attribute. That means {"user":{"id":"42","name":"Ana"}} produces <user><id>42</id><name>Ana</name></user>, not <user id="42"><name>Ana</name></user>. This post explains why, how to reshape the output when you need attributes, and when you should skip the browser tool for a code library.
Why Element-Only Output Is the Safe Default
JSON has one way to name a value: a key. XML has two — element name or attribute. Every JSON-to-XML tool has to pick a rule. Our converter picks "everything becomes an element" because:
- It's lossless. Every JSON field has a visible, predictable XML form. Nothing gets silently demoted or skipped.
- It maps cleanly to SOAP. Most SOAP bodies are element-only. Attribute-heavy XML is more common in config files and markup.
- It's deterministic. You don't need a schema to know which JSON fields become attributes. The output only depends on the input structure.
The tradeoff: if your target schema requires attributes, you have to reshape after conversion. For most one-off use cases — debugging, building test fixtures, docs — elements are what you want anyway.
Workaround 1 — XSLT Post-Process for Attributes
If you repeatedly need specific fields as attributes, write a short XSLT that promotes them. Example — turn <user><id>42</id><name>Ana</name></user> into <user id="42"><name>Ana</name></user>:
<xsl:template match="user">
<user id="{id}">
<xsl:copy-of select="*[not(self::id)]"/>
</user>
</xsl:template>
Run it with any XSLT processor — xsltproc on Linux, Saxon in Java, or an XSLT npm package. Reusable across every payload.
Workaround 2 — Hand-Edit for 2-3 Attributes
Writing XSLT for a single one-time payload is overkill. If you only need a couple of attributes, convert to elements, then find-and-replace in any text editor:
- Convert JSON to XML in the browser tool.
- Copy the output into VSCode, Sublime, or any editor.
- Find
<user><id>(\d+)</id>— replace with<user id="$1">.
Fast, visible, no new code. Only works when the pattern is simple and the volume is low.
When to Skip the Browser Tool Entirely
If attributes are a hard requirement inside a service, use a library that exposes attribute rules as configuration:
- Jackson XmlMapper (Java) — annotate fields with
@JacksonXmlProperty(isAttribute = true)to mark them as attributes. - xmltodict (Python) — use the
@prefix in dict keys to mark attributes:{"user": {"@id": "42", "name": "Ana"}}. - xml2js (Node) — use the
$key convention for attributes in the input object.
These give you a declarative rule instead of a post-processing step. For a browser tool that's one paste-and-click away, element output stays predictable.
Deciding — Do You Actually Need Attributes?
Most of the time, the answer is no. If you're:
- Debugging a SOAP body — elements are fine; most services accept both.
- Building a test fixture — use whatever shape the consumer expects, but don't invent attributes where elements work.
- Generating XML from a REST payload for a legacy partner — ask them for the exact schema; they often accept element-only.
Attributes are only mandatory when the receiving XSD says they're mandatory. Check the schema before you chase an attribute-output converter.
Convert Now — Post-Process Later if You Need Attributes
Element-only output works for 95% of JSON-to-XML needs. Paste your JSON, get clean XML in one click.
Open Free JSON to XML ConverterFrequently Asked Questions
Why can't I just configure the tool to output attributes?
Because there's no universal rule for which JSON keys should become attributes. Some libraries use a @-prefix convention, some use annotations, some take a config file. Adding that config to a paste-and-click tool would make it slower to use for the 95% case where elements are fine.
How do I know if my XML target needs attributes or elements?
Check the target XSD schema or a sample response from the service. If the sample has id="42" in angle brackets, you need attributes. If it has
Can XSLT 3.0 convert JSON directly to attribute-heavy XML?
Yes — XSLT 3.0 has xsl:map and can ingest JSON with fn:json-to-xml(). If you're already running XSLT, you can skip the browser tool entirely and do the whole conversion in one template.
Does SOAP require element output or attribute output?
SOAP bodies are overwhelmingly element-based. Attributes show up mostly in WSDL definitions and SOAP headers (like wsu:Id). The browser tool's element output is what 99% of SOAP operations expect.

