К блогу
guide 2026-06-14

JSON, YAML, XML, CSV — Round-Tripping With One Toolbox (2026)

JSON, YAML, XML, CSV — Round-Tripping With One Toolbox

If you're a developer in 2026, you've probably opened 30 browser tabs this month named something like "json to yaml online" or "csv to xml converter free." Every project, every CI pipeline, every cross-team data drop needs at least one format-to-format hop: the analytics team exports CSV, the platform team expects YAML, the partner integration runs on XML, and you keep glueing them with one-off Python scripts that work great until somebody's name contains a comma and a unicode emoji.

This guide explains the four canonical data-interchange formats every backend developer needs to fluently read and write, why each exists, and how to use Ai2Done's developer toolbox to round-trip between them safely — including the JSON formatter, XML formatter, YAML formatter, and converters like CSV to Excel, XML to JSON, and XML to CSV — all running 100% in your browser.

TL;DR

  • JSON is the modern default — use it unless you have a reason not to.
  • YAML is JSON with comments and less punctuation — use it for config files humans will read and edit.
  • XML is the format your enterprise integrations still demand — use it when the other side won't compromise.
  • CSV is the format business stakeholders will actually open — use it for analytics, exports, and anything destined for Excel.
  • Round-tripping (JSON → YAML → JSON) is almost always lossless. CSV ↔ JSON is not lossless when your JSON has nested structures — flatten or denormalise deliberately.

Why this is harder than it looks

A naive engineer thinks "data format conversion is just JSON.parse and JSON.stringify with different syntax." In practice every format has subtle traps that bite during real production use:

JSON has no comments, no trailing commas, no undefined, no Date type, no Map, and no BigInt. Numbers above 2^53 silently lose precision in JavaScript. Strings must be UTF-8 (no \r\n line breaks unescaped). A surprising number of "JSON" files written by Java or .NET aren't quite valid JSON because they ship as JSON-with-comments or JSON-with-trailing-commas.

YAML is famously over-flexible — the spec is 80 pages, the yes/no/on/off boolean shorthand silently parses Norway's country code "NO" as false, and indentation errors produce wildly different parses across libraries. A YAML document that loads correctly in Ruby may load differently in Python or Go because YAML 1.1 vs YAML 1.2 vs custom-style differences.

XML is verbose but unambiguous. Its real complication is namespaces (the xmlns: prefix nonsense) and attributes vs child elements — different XML writers represent the same logical data in completely different ways. There's also the choice of CDATA vs entity-escaping for special characters, which can break consumers expecting one or the other.

CSV is the worst of all because there is no real spec. Different tools use different quoting rules, different escape characters, and different handling of line breaks inside cells. Microsoft Excel writes "CSV" that opens incorrectly in Google Sheets and vice versa. UTF-8 vs Windows-1252 encoding mismatches turn "Pokémon" into "Pokémon" in roughly 30% of real-world CSV exports.

A good format converter does two non-obvious things: it (1) tolerates non-strict input from real-world tools, and (2) emits strict output that downstream tools will reliably accept. Most online converters do neither.

Method 1: Ai2Done format tools (browser-side)

The Ai2Done format hub has individual tools for each format plus several conversion pairs. The flow for any conversion:

  1. Open the tool — e.g. JSON Formatter or XML to JSON.
  2. Paste your input (or drop a file) into the left panel.
  3. The output appears instantly in the right panel — formatting and conversion happens as you type, locally in your browser.
  4. Copy or download the result. For files, the tool produces a single output document or a ZIP if the input contained multiple documents.

Common workflows our users hit:

  • JSON → YAML: open JSON formatter, paste JSON, the YAML output appears in the "Convert to" panel. Reverse with YAML formatter.
  • CSV → JSON: paste CSV, the tool detects delimiter (comma, tab, semicolon, pipe) and quotes automatically. First row treated as headers unless you uncheck.
  • XML → JSON: paste XML, the tool handles namespaces by prefixing keys with the namespace alias. Attributes become @attr keys, text content becomes #text.
  • XML → CSV: with the XML to CSV tool, the tool flattens repeating elements into rows (you pick which element type is the "row" boundary).
  • CSV → Excel: with CSV to Excel, the tool produces a real .xlsx (not a renamed CSV), respecting UTF-8 encoding so Chinese, Japanese, and emoji round-trip correctly.

Everything runs in your browser. JSON, YAML, and XML parsing use battle-tested libraries (ajv for JSON Schema validation, js-yaml for YAML, fast-xml-parser for XML) compiled into a single ~150 KB bundle.

Method 2: jq + yq + xmlstarlet on the command line

For developers who live in the terminal, the canonical stack is:

# JSON
cat data.json | jq '.'

# YAML
cat data.yaml | yq '.'                   # mikefarah's Go yq
yq -o=json '.' data.yaml > data.json     # YAML → JSON

# XML
xmlstarlet sel -t -c '/' data.xml         # pretty-print

# CSV → JSON
csvkit:  csvjson data.csv > data.json
mlr (Miller): mlr --c2j cat data.csv

The advantages: scriptable, composable in pipelines, no browser tab needed. The disadvantages: each tool has its own DSL to learn, none of them handles all four formats, and you end up writing a small Makefile or justfile of one-off conversions per project.

This is the right choice when you have repeated, automated conversion (a nightly cron job that pulls a CSV from an FTP server and pushes JSON to an API). It's overkill for a Tuesday-afternoon "I need this CSV as JSON so I can paste it into Postman" task.

Method 3: Pandas (when the data is the point)

If your conversion task is really a data transformation task disguised as a format conversion — pivot the rows, drop columns, filter, dedupe, then output — reach for pandas:

import pandas as pd
df = pd.read_csv('input.csv')
df = df[df['status'] == 'active']
df = df.drop_duplicates(subset='email')
df.to_json('output.json', orient='records', force_ascii=False)

Pandas reads/writes CSV, Excel, JSON, Parquet, SQL, and a dozen others. It's the right answer when your CSV has 500K rows and you need to do something analytical before writing the output. For a 50-row data file you wanted converted in 5 seconds, it's massive overkill — pip install pandas alone takes 30 seconds.

How we built the format tools (technical deep-dive)

The Ai2Done format toolbox is built around a shared canonical intermediate representation — once any input is parsed (JSON, YAML, XML, CSV), it becomes a plain JavaScript object tree. All conversions then become "serialise the tree to format X." This means we only need N parsers and N serialisers, not N² converters.

The interesting engineering challenges:

  • XML's attributes vs children problem. We use the conventional @attr prefix for attributes and #text for text content, then offer a "round-tripping mode" in the UI that preserves this losslessly. You can convert XML → JSON → XML and get the same XML out (modulo whitespace).
  • CSV header inference. We sniff the first 5 rows: if row 1 has all-text values and row 2+ has numeric values, row 1 is headers. If unclear we ask. This catches ~95% of real CSV files correctly without configuration.
  • YAML safety. We use js-yaml's safeLoad to avoid the infamous YAML 1.1 !!python/object code-execution exploit that haunted Ruby's YAML library for years. No user-supplied YAML can execute code in your browser.
  • BigInt and high-precision numbers. JSON parsers in JavaScript silently lose precision for integers above Number.MAX_SAFE_INTEGER. Our parser detects these (15+ digit integers, scientific notation past 17 sig figs) and offers to preserve them as strings with a "_bigint:..." marker — opt-in, because most users don't care.
  • UTF-8 BOM handling. The Excel-exported "CSV with BOM" that breaks 30% of online converters works fine here — we detect and strip the byte-order mark on input, optionally re-add it on output if you toggle "Excel compatibility."

Everything is compiled to a single ~400 KB gzipped JS bundle that loads on first visit. After that, all conversions are instant (sub-millisecond for files under a few MB).

FAQ

Q: Why do I lose data when converting nested JSON to CSV? A: CSV is fundamentally a 2D table. Nested JSON ({a: {b: {c: 1}}}) has no native CSV representation. Our tool offers two strategies: flatten (produces columns like a.b.c) or explode (one row per leaf — usually not what you want). Pick deliberately; there is no "right" answer.

Q: My CSV has commas inside cells. Will the converter handle it? A: Yes — we follow RFC 4180. Cells with commas, line breaks, or double quotes are auto-quoted with "..." and any inner quotes are doubled to "". This matches Excel, Google Sheets, and the Python csv module.

Q: Can I validate JSON against a JSON Schema in the browser? A: Yes, the JSON Formatter has a Schema tab where you paste a schema and get inline validation errors. We use ajv under the hood (the fastest JSON Schema validator in JavaScript).

Q: My XML has namespaces. Will the converted JSON keep them? A: Yes — namespace-prefixed elements become JSON keys like "ns:elementName". The namespace declarations move to a @xmlns key on the root. Reversing the conversion produces equivalent (though potentially differently-formatted) XML.

Q: What's the difference between YAML 1.1 and YAML 1.2 in your parser? A: We default to YAML 1.2 (which fixes the Norway problem — NO is the string "NO", not the boolean false). You can switch to YAML 1.1 mode for compatibility with old Ruby or Symfony configs that depend on the legacy boolean shorthand.

Q: Can I batch-convert 100 CSV files to JSON at once? A: Yes — drop all 100 files into the tool, click Convert, get a ZIP back. Each file is processed in its own Web Worker so a multi-core machine processes them in parallel.

Try it now

Pick the conversion you need:

Browse the full developer toolbox.

Related reading


Last updated 2026-06-14. All format conversion tools run 100% in your browser — your data never leaves your device. We never collect, log, or analyse the content you process.