Skip to content
Developers

How to Format JSON, XML and YAML Online (and Fix Errors)

JSON vs XML vs YAML compared, how to format and validate each, the syntax errors that break them and how to fix them, plus converting between formats.

Written byAI Online Tools editorial teamUpdated 5 min readPublished

To format JSON, XML or YAML online, paste it into a formatter, choose 2 or 4 spaces of indentation and click Format. The tool parses the data first, so if anything is broken it points to the exact line and column. Once it's valid, you can also convert it: JSON to CSV for a spreadsheet, XML to JSON for an API, or YAML to JSON for a script.

Tools used in this guide

All free, with no sign-up. They run in your browser.

JSON vs XML vs YAML at a glance

All three formats store structured data: values, lists and nested groups. They differ in how strict and how readable they are.

JSONXMLYAML
Looks like{"name": "Asha"}<name>Asha</name>name: Asha
Structure fromBraces and bracketsOpening and closing tagsIndentation
CommentsNot allowed<!-- like this --># like this
Data typesString, number, true/false, null, array, objectEverything is text unless a schema says otherwiseStrings, numbers, booleans, null, lists, maps (guessed from the value)
Attributes / metadataNoYes (<total currency="INR">)No
StrictnessVery strict, easy to parseStrict, verboseForgiving to write, easy to get subtly wrong
Typical useWeb APIs, app settings, package.jsonSitemaps, RSS, SOAP, Office files, invoices and bank feedsDocker Compose, Kubernetes, GitHub Actions, CI config

Here is the same small record in all three:

{ "order": { "id": 1001, "customer": "Asha Verma", "paid": true, "items": ["kurta", "dupatta"] } }
<order id="1001">
  <customer>Asha Verma</customer>
  <paid>true</paid>
  <items><item>kurta</item><item>dupatta</item></items>
</order>
order:
  id: 1001
  customer: Asha Verma
  paid: true
  items:
    - kurta
    - dupatta

How to format and validate each format

JSON

Paste your data into the JSON formatter, or upload a .json file. Then:

  1. Click Validate to check the syntax. Valid JSON gets a green message; broken JSON gets a plain-language error with its line and column.
  2. Click Format to pretty-print it with 2 or 4 spaces.
  3. Click Minify when you need the smallest version, for example to paste into an environment variable.
  4. If validation fails, try Auto-fix. It repairs the three most common problems — trailing commas, single quotes and unquoted keys — and wraps several separate objects into one array.
  5. Copy the result or download it as formatted.json.

XML

The XML formatter works the same way. Validate checks that the document is well-formed: every tag closed, properly nested, one root element. Format indents it, Minify strips the whitespace between tags, and Tree view shows the structure as a collapsible outline, which helps with deeply nested feeds. It can also turn the XML into JSON in one click.

Note: "Well-formed" and "valid" are different in XML. Well-formed means the syntax is correct. Valid means it also matches a schema (XSD or DTD) that defines which tags are allowed. Online formatters check the first; schema validation needs the schema file.

YAML

YAML has no braces to count, so mistakes are easy to miss by eye. The quickest check is to run it through the YAML to JSON converter. If the YAML is broken, you get the line and column of the problem. If it converts, read the JSON output: it shows exactly how the parser understood each value, which catches type surprises (more on those below).

Common syntax errors and how to fix them

JSON errors

ErrorBrokenFixed
Trailing comma{"a": 1, "b": 2,}{"a": 1, "b": 2}
Single quotes{'name': 'Asha'}{"name": "Asha"}
Unquoted key{name: "Asha"}{"name": "Asha"}
Missing comma{"a": 1 "b": 2}{"a": 1, "b": 2}
Comments{"a": 1} // noteRemove the comment
Not-a-value{"total": NaN} or undefinedUse null or a number
Unescaped quote in text"He said "hi"""He said \"hi\""

Browser error messages can be cryptic. "Expected double-quoted property name" usually means a trailing comma just before a }. "Expected ',' or '}' after property value" means a missing comma. The column number marks where the parser gave up, which is usually just after the real mistake, so look a little to the left of it.

XML errors

  • Tag not closed or wrongly nested: <a><b>x</a> — close the inner tag first: <a><b>x</b></a>.
  • Case mismatch: <Item>x</item> — XML is case-sensitive, so both tags must match exactly.
  • Bare ampersand or less-than sign: <name>Fish & Chips</name> — write &amp; and &lt;, or wrap the text in <![CDATA[ … ]]>.
  • Unquoted attribute: <order id=1001> — attributes always need quotes: id="1001".
  • More than one root element: wrap everything in a single parent such as <orders> … </orders>.
  • Text before the declaration: <?xml version="1.0"?> must be the very first thing in the file, with no blank line or space before it.

YAML errors

  • Tabs for indentation. YAML forbids tabs. Replace them with spaces (2 is the convention) and set your editor to insert spaces.
  • Inconsistent indentation. A key indented one space more than its siblings becomes a nested child, or an error. Keep each level at the same depth.
  • No space after the colon. name:value is read as one string, not a key and value. Write name: value.
  • A colon inside a value. title: Error: not found breaks. Quote it: title: "Error: not found".

YAML also guesses types, and the guesses can surprise you. Our converter reads YAML 1.2, and running it shows these real results:

You wroteParsed asFix
version: 1.101.1 (a number)version: "1.10"
zip: 012341234 (leading zero lost)zip: "01234"
enabled: yes"yes" (text) in YAML 1.2, but true in older YAML 1.1 parsers such as PyYAMLUse true / false
country: NO"NO" in YAML 1.2, but false in YAML 1.1 parserscountry: "NO"

Tip: When in doubt, quote it. Quoted values are always strings in every YAML parser.

Converting between JSON, XML, YAML and CSV

JSON to CSV or Excel (for spreadsheets)

The JSON to CSV converter turns an array of objects into rows. Each key becomes a column, and any value containing a comma or quote is wrapped in quotes so it stays in one cell.

[
  { "id": 1, "name": "Asha", "city": "Pune", "plan": "Pro" },
  { "id": 2, "name": "Rahul", "city": "Kochi", "plan": "Free" },
  { "id": 3, "name": "Meera, R.", "city": "Delhi", "plan": "Pro" }
]

becomes:

id,name,city,plan
1,Asha,Pune,Pro
2,Rahul,Kochi,Free
3,"Meera, R.",Delhi,Pro

CSV is a flat table, so it works best with flat records. If your objects contain nested objects or lists, use JSON to Excel instead. It flattens nested fields into dotted column names and downloads a real .xlsx file. For example, {"id": 1, "address": {"city": "Pune", "pin": "411001"}, "tags": ["new", "vip"]} becomes the columns id, address.city, address.pin, tags.0 and tags.1.

XML to JSON (for APIs and scripts)

The XML to JSON converter follows three simple rules. Attributes become keys starting with @. An element's own text, when it also has attributes, becomes #text. Repeated elements become an array, and numbers and booleans in element text are typed.

<orders>
  <order id="1001" status="paid">
    <customer>Asha Verma</customer>
    <total currency="INR">2499</total>
  </order>
  <order id="1002" status="pending">
    <customer>Rahul Nair</customer>
    <total currency="INR">799</total>
  </order>
</orders>

becomes:

{
  "orders": {
    "order": [
      { "@id": "1001", "@status": "paid", "customer": "Asha Verma",
        "total": { "@currency": "INR", "#text": 2499 } },
      { "@id": "1002", "@status": "pending", "customer": "Rahul Nair",
        "total": { "@currency": "INR", "#text": 799 } }
    ]
  }
}

Warning: A single <order> becomes an object, but two or more become an array. If your code always expects an array, handle the one-item case too.

YAML to JSON (for tools that only read JSON)

YAML to JSON is useful when a script, API or validator only accepts JSON. It also shows how a config file is really being read.

app:
  name: invoice-api
  port: 8080
  debug: false
  allowed_origins:
    - https://example.com
    - https://admin.example.com
  version: 1.10

becomes:

{
  "app": {
    "name": "invoice-api",
    "port": 8080,
    "debug": false,
    "allowed_origins": ["https://example.com", "https://admin.example.com"],
    "version": 1.1
  }
}

Notice the last line: 1.10 turned into 1.1. That's the type-guessing problem from the table above, caught before it reached production. The same converter works in reverse (JSON to YAML), and a file with several YAML documents separated by --- becomes a JSON array.

Keep your data private: why browser tools matter

Config files and API responses often contain things you shouldn't paste into a random website: API keys, customer names, phone numbers, internal hostnames.

The formatters and converters on this site run in your browser. The JSON and XML formatters parse with your browser's own engine. The converters use JavaScript libraries loaded into the page. Either way, your data isn't sent to a server for processing. Even so, a few habits help:

  • Remove secrets before pasting anywhere, and rotate any key you've accidentally shared.
  • Use sample data when asking for help on a forum or in a chat.
  • Check what a tool does with your input. If a site uploads your file to a server, assume it's stored somewhere.

Bookmark the two formatters, and keep the converters for the moments when one system speaks a different format from the next.

Frequently asked questions

What is the difference between formatting and validating JSON?

Validating checks that the text follows JSON's rules and tells you where it breaks. Formatting rewrites valid JSON with consistent indentation and line breaks. A formatter has to parse the JSON first, so it validates as a side effect.

Can JSON have comments?

No. Standard JSON has no comment syntax, so // or /* */ makes it invalid. Some tools accept JSONC (JSON with comments), but plain JSON.parse and most APIs reject it.

Is YAML a superset of JSON?

YAML 1.2 was designed so that almost any JSON document is also valid YAML. The reverse is not true: comments, anchors and unquoted strings in YAML have no JSON equivalent.

Why did my ZIP code or PIN lose its leading zero after converting YAML?

Unquoted 01234 in YAML is read as the number 1234. Put values such as PIN codes, phone numbers and version numbers in quotes, for example zip: "01234", so they stay text.

All guides