JSON, YAML and XML compared: differences and how to convert between them
Published by InstantToolDeck · Updated November 2026
JSON, YAML and XML all describe structured data, but each was designed with different goals. Here is the same record in each format.
The same data three ways
JSON
{"name": "Ada", "languages": ["en", "fr"], "active": true}
YAML
name: Ada languages: - en - fr active: true
XML
<person> <name>Ada</name> <languages><item>en</item><item>fr</item></languages> <active>true</active> </person>
When to use which
- JSON: web APIs and data exchange. Strict, compact and supported everywhere.
- YAML: configuration people edit by hand, such as Kubernetes, GitHub Actions and Docker Compose. Supports comments and is easy to read.
- XML: documents with mixed text and markup, older enterprise and SOAP systems, RSS feeds and many office file formats. Has attributes and namespaces.
Converting between them
Use the YAML ⇄ JSON converter and the JSON ⇄ XML converter. Conversion is straightforward for plain data, but a few things do not translate perfectly:
- YAML comments are lost in JSON, which has no comments.
- XML has no number or boolean types, so values come back as strings.
- XML attributes have no direct JSON equivalent. A common convention is an
@prefix, which the converter uses. - YAML can read unquoted values such as
yes,noor1.0as booleans or numbers. Quote values that must stay text.
Validate first
If a conversion fails, fix the source. The JSON formatter reports the line and column of errors, and the YAML converter reports indentation problems with line numbers.
Typed code from JSON
When you work in TypeScript, the JSON to TypeScript converter turns a sample payload into interfaces.
Frequently asked questions
Is YAML better than JSON?
Neither is better. YAML is friendlier for human-edited config, while JSON is stricter and better for data exchange between programs.
Is every JSON file valid YAML?
Almost always. YAML 1.2 was designed as a superset of JSON, so most JSON parses as YAML.
Why does XML to JSON turn numbers into strings?
XML stores all values as text. Without a schema the converter cannot know which values are numbers.
Which format is smallest?
JSON is usually more compact than XML. YAML is often similar to JSON in size, but depends on indentation.