Learn/Comparisons & Conversions

Convert JSON to CSV, XML, YAML & More

JSON doesn't live in isolation — you constantly need to move data between formats. This guide covers every major conversion path, including edge cases that trip up experienced developers.

Beginner~14 min read

Conversion Map

JSON Conversion Paths

JSON → CSV

The most common conversion. Works best with flat arrays of objects that share the same keys.

Input JSON

[
{ "name": "Alice", "age": 28, "city": "SF" },
{ "name": "Bob", "age": 34, "city": "NYC" }
]

Output CSV

name,age,city
Alice,28,SF
Bob,34,NYC

Edge Cases to Watch

ProblemSolution
Nested objectsFlatten first: user.address.city → separate column
Arrays in valuesJoin with separator: ["a","b"] → "a;b"
Missing keysFill with empty string or null
Commas in valuesQuote the field: "San Francisco, CA"
Unicode charactersUse UTF-8 BOM for Excel compatibility

Use Our Tool

JSON to CSV converter handles nested flattening, array explosion, and UTF-8 BOM automatically.

JSON → XML

JSON and XML have fundamentally different data models. Key decisions during conversion:

JSON ConceptXML MappingExample
Object keyElement name"name": "Alice" → <name>Alice</name>
ArrayRepeated elements["a","b"] → <item>a</item><item>b</item>
nullEmpty element or attributenull → <value xsi:nil="true"/>
Number/BooleanText content42 → <age>42</age> (type info lost)
JSON → XML conversion examplexml
1<!-- Input: {"user": {"name": "Alice", "roles": ["admin", "editor"]}} -->
2<root>
3 <user>
4 <name>Alice</name>
5 <roles>
6 <item>admin</item>
7 <item>editor</item>
8 </roles>
9 </user>
10</root>

Data Loss Risk

XML does not distinguish between numbers and strings — everything is text. JSON 42 and "42" both become <value>42</value>. Round-tripping is not guaranteed.

JSON → YAML

The most straightforward conversion — JSON is valid YAML, so the mapping is almost 1:1.

JSON

{
"server": {
"host": "0.0.0.0",
"port": 3000,
"debug": false
}
}

YAML

server:
host: "0.0.0.0"
port: 3000
debug: false

YAML Auto-Type Pitfall

YAML treats on/off/yes/no as booleans, 3.10 as float 3.1. Always quote ambiguous strings when converting.

JSON → Markdown

Converting JSON to Markdown is useful for documentation, README files, and reports.

Array of objects → Markdown tabletext
1| name | age | city |
2|-------|-----|------|
3| Alice | 28 | SF |
4| Bob | 34 | NYC |

Reverse Conversions

CSV → JSON

Each CSV row becomes a JSON object. The header row provides the keys. Handle type inference carefully — everything in CSV is a string by default.

Type inference strategyjavascript
1// Raw CSV parse: { "age": "28", "active": "true" }
2// With type inference: { "age": 28, "active": true }
3// Rule: parse numbers, booleans, and null; keep everything else as string

XML → JSON

The hardest reverse conversion. Decisions: should XML attributes become properties? Should text nodes be extracted? How to handle namespaces?

Conversion Best Practices

Always validate output after conversion
Flatten nested JSON before converting to CSV
Quote ambiguous values when converting to YAML
Use UTF-8 encoding for all conversions
Test with edge cases: null, empty arrays, deep nesting
Keep a copy of the original JSON before transforming
Use streaming for files over 50 MB
Check for data type loss in XML round-trips

Try It Yourself

Here's a JSON array. Think about how this would map to CSV columns, XML elements, and YAML structure.

Try It Yourself

Validate this JSON, then try our converter tools above

Frequently Asked Questions

Can I convert JSON to CSV without losing data?
Flat JSON (array of objects with the same keys) converts perfectly. Nested objects and arrays require flattening first, which may change the structure. Always verify the output.
How do I convert JSON to XML?
Use a converter tool or library. Key decisions: should JSON keys become XML elements or attributes? How should arrays map? Our JSON to XML tool handles these automatically.
Is JSON to YAML lossless?
Nearly. Both formats support the same data types. The only risk is YAML auto-type detection (e.g., "yes" becomes boolean true). Quote ambiguous strings to prevent this.
What is the best way to convert large JSON files?
Use streaming parsers for files over 100 MB. For smaller files, our browser-based tools handle conversion locally without uploading your data.
Can I convert JSON to Excel directly?
Convert JSON to CSV first, then open the CSV in Excel. For nested JSON, flatten it first using a JSON Flattener, then export to CSV.