Guides

JSON, YAML, TOML and XML: which format when

All four store the same kind of thing, nested keys and values, but each was designed for a different reader. JSON is for programs talking to programs, YAML and TOML are for people editing configuration, and XML is for documents and the systems that grew up around them. This guide covers what each is good at, the traps that catch people, and what happens to your data when you convert between them.

By Radhika Singh · Last updated

The short answer

Pick by who reads and writes the file most often. If it is a program, use JSON. If it is a person editing settings, use YAML when the settings nest deeply and TOML when they are mostly flat. Use XML when a standard or an existing system already requires it.

FormatBest forCommentsTypesYou see it in
JSONAPIs, data exchange, browser storageNoString, number, true/false, null, array, objectREST APIs, package.json, web app state
YAMLConfiguration people edit, with deep nestingYes (#)JSON's types, guessed from the text unless quotedKubernetes, GitHub Actions, Docker Compose
TOMLConfiguration that is mostly flatYes (#)Explicit, including dates and timesCargo.toml, pyproject.toml
XMLDocuments and long-lived integrationsYes (<!-- -->)Text, unless a schema says otherwiseSOAP, RSS and sitemaps, Office files, SVG

JSON: the default for data between programs

JSON (RFC 8259) has six kinds of value and very few rules, which is why every language reads it. The rules it does have are strict: keys must be in double quotes, trailing commas are errors, and there are no comments. A config file that needs explanations is the clearest sign JSON is the wrong choice for it.

One trap matters in practice: JavaScript reads every JSON number as a 64-bit float, so integers above 9,007,199,254,740,991 (2^53 − 1) silently lose precision. IDs from databases and payment systems are often sent as strings for exactly this reason. Keep them as strings when you convert.

For logs and large exports, JSON Lines puts one complete object on each line so a file can be streamed and appended; the JSON Lines converter turns an array into lines and back. To ship JSON smaller, minify it; to put JSON inside a string, such as a config value or a test fixture, escape it; to pull values out of a large response, try a JSONPath expression in the JSONPath tester or a jq filter in the jq playground.

YAML: configuration written by people

YAML replaces JSON's brackets with indentation and adds comments, multi-line strings and anchors (define a block once, reuse it with an alias). YAML 1.2 was designed so that valid JSON is also valid YAML, which is why converting JSON to YAML is safe while the reverse can surprise you.

The surprises come from implicit typing: YAML decides what a value is from how it looks. Under YAML 1.1 rules, which many parsers still follow, yes, no, on and off become booleans, so a list of country codes turns NO (Norway) into false. A version written 3.10 becomes the number 3.1. Quote anything that must stay text. Indentation must use spaces; a tab in the indentation is an error.

Before committing a CI or Kubernetes file, run it through a YAML validator. To see exactly what a parser will read, convert it with YAML to JSON: the JSON shows every guessed type explicitly. JSON to YAML goes the other way when a tool wants YAML and your data is JSON.

TOML: flat configuration with explicit types

TOML (version 1.0.0, January 2021) looks like an INI file with real types: key = value lines, [table] headers for sections, and native dates and times, so 2026-11-29 is a date and not a string to parse later. Nothing is guessed: strings are always quoted, so the Norway problem cannot happen.

It is the standard for Rust packages (Cargo.toml) and Python projects (pyproject.toml). Its weakness is deep nesting: three or four levels means long dotted headers such as [server.http.tls], and lists of tables use the [[double bracket]] syntax that newcomers often misread. To check how a TOML file is structured, convert it with TOML to JSON.

XML: documents, schemas and long-lived systems

XML is markup first: elements can contain text, other elements and attributes, which suits documents (SVG images, Office files, which are zipped XML, RSS feeds and sitemaps) and the enterprise integrations built on SOAP and XML Schema. Namespaces and schemas make it verbose, but they also make it possible to validate a message against a contract.

Converting XML to JSON has two decisions with no single right answer. Attributes and child elements both become keys, so a converter marks attributes with a prefix. And an element that appears once looks like a single object, while the same element repeated becomes an array, so code that reads the JSON must handle both. The XML to JSON converter lets you set both, attributes as @name keys and repeated elements always as arrays, so the shape is predictable before you write code against it; JSON to XML builds XML from JSON when a system expects it.

If you parse XML in your own code, turn off DTD and external entity processing. Entity expansion is the basis of the XXE and billion laughs attacks; this site's converter removes the DOCTYPE before parsing for that reason.

Spreadsheets and TypeScript

Two conversions come up constantly at the edges of these formats. People who live in spreadsheets need JSON as rows and columns: JSON to Excel flattens an array of objects into a sheet, and Excel to JSON reads a sheet back as objects, including Excel's serial dates. Developers who receive JSON need types: JSON to TypeScript writes interfaces from a sample. Types inferred from one sample are only as complete as that sample, so feed it a response that includes optional fields.

A checklist for choosing

When the choice is still open:

  • Programs on both ends, no human editing: JSON.
  • People edit it and it needs comments: YAML or TOML, never JSON.
  • Deep nesting (Kubernetes manifests, CI pipelines): YAML. Mostly flat settings: TOML.
  • A standard, a partner or an existing system requires it: XML, and validate against its schema.
  • Values that must stay exact (IDs, versions, ZIP codes): store them as quoted strings in every format.

Whatever you pick, convert once at the boundary and keep one format inside your own code.

The tools in this guide

JSON MinifierPaste JSON and get it on one line with every unnecessary space and line break removed, plus how many bytes you saved.JSONPath TesterPaste JSON, type a JSONPath expression, and see every matched value and its path live, with matches highlighted in the source.JSON Escape & UnescapeEscape text so it is a valid JSON string, or turn an escaped JSON string back into plain text.JSON to JSON Lines ConverterTurn a JSON array into JSON Lines, one object per line, or combine JSON Lines back into an array.YAML to JSON ConverterPaste YAML and get the equivalent JSON, with the line and column of any error.JSON to YAML ConverterPaste JSON and get readable YAML, with values that older YAML readers would misread quoted automatically.TOML to JSON ConverterConvert TOML to JSON and back; Swap flips the direction and carries the result over.JSON to XML ConverterPaste JSON and get well-formed, indented XML, with attributes, text and arrays mapped by clear rules.XML to JSON ConverterPaste XML and get JSON, with attribute and array rules you can see and change.JSON to Excel ConverterPaste or upload a JSON array and download a real .xlsx workbook, with nested fields flattened into columns and a preview first.Excel to JSON ConverterOpen an .xlsx, .xls or .csv file, pick a sheet, and get an array of JSON objects keyed by the header row.JSON to TypeScript GeneratorPaste a JSON sample and get TypeScript interfaces or type aliases for it, nested objects included.jq PlaygroundRun real jq filters on pasted JSON and see the output as you type.

Found a mistake? Write in from the About page and it gets fixed.

Pick a tool.
Get it done.

125 utilities today, more every month. Bookmark the one you reach for.