Which format should you actually convert to?
Converting between JSON, CSV, XML, and YAML is rarely lossless. Knowing where each
conversion drops information saves you from discovering it in production.
JSON to CSV loses structure. CSV is a flat grid; JSON is a tree. Any nested
object or array has to be flattened into columns like address.city, or serialised
back into a string inside a cell. CSV also has no type system — every value arrives as text, so
"1", "true", and "null" come back as strings and a
leading-zero postcode like 01234 gets mangled into the number 1234 by whatever
reads it. Use CSV when the destination is a spreadsheet, not when it is another program.
YAML is a superset of JSON, so every valid JSON document is already valid
YAML. Going the other way is where it gets interesting. YAML's implicit typing is famously
surprising: in the YAML 1.1 spec that many parsers still follow, the unquoted value
no parses as the boolean false, which is why the country code for
Norway has broken so many config files that the behaviour has a nickname — the Norway problem.
Unquoted 1.0 becomes a float, and 08 can error as an invalid octal.
If a YAML value must stay a string, quote it.
XML distinguishes attributes from elements; JSON does not. Every
JSON-to-XML converter has to invent a convention for that round trip, commonly prefixing
attribute keys with @ and putting text content under something like
#text. Two converters will not necessarily agree, so an XML document that survives
a round trip through one library may not survive another.
Reading a JSON parse error
Most invalid JSON fails for one of four reasons, and the error message usually points a few
characters past the real culprit rather than at it.
-
A trailing comma after the last element. Legal in JavaScript object
literals, illegal in JSON. This is the single most common cause.
-
Single quotes. JSON strings and keys require double quotes.
{'a': 1} is a JavaScript object, not JSON.
-
Unquoted keys.
{a: 1} is likewise JavaScript, not JSON.
-
A raw newline or tab inside a string. Control characters must be escaped
as
\n and \t. This is what a JSON escaper is for.
One thing a validator will not catch: JSON numbers have no precision limit in the spec, but
JSON.parse maps them onto IEEE-754 doubles. Any integer above 253 — a
Twitter/X status ID, a Discord snowflake, a large database key — loses precision silently. If
an API returns large integer IDs, it should send them as strings, and if it doesn't, you cannot
fix it in the browser after the fact.
Frequently Asked Questions
Why does my JSON fail to parse when it looks correct?
Usually a trailing comma after the final array element or object property, single
quotes instead of double quotes, or an unquoted key. All three are legal JavaScript and
illegal JSON, so code that was copied out of a .js file often fails.
Parser errors typically report the position just after the problem, not at it.
Is my data uploaded to a server?
No. Every JSON, CSV, XML, and YAML tool on this page parses and converts your input in
your browser using JavaScript. Nothing is transmitted to ToolzYard, which matters if
you are debugging a payload that contains production data or credentials.
Why did my large ID numbers change after formatting?
JavaScript parses JSON numbers as IEEE-754 doubles, which represent integers exactly
only up to 253 − 1 (9,007,199,254,740,991). Anything larger — snowflake IDs,
big primary keys — is rounded on parse. The fix belongs on the API side: send such
values as JSON strings.
Why did "NO" become "false" when I converted to YAML?
YAML 1.1 implicit typing treats unquoted no, yes,
on, and off as booleans. It is the reason Norway's country
code NO famously breaks config files. Quote any string value whose type
must survive the round trip.
Can I convert nested JSON to CSV?
Only by flattening it first. CSV is a flat grid with no concept of nesting, so nested
objects become dotted column names such as user.address.city, and arrays
either explode into multiple columns or get serialised into a single cell. Use the JSON
Flatten tool before converting if you want control over how that happens.