JSON ↔ YAML Converter

Convert between JSON and YAML, validate the structure and see how each value type is written in the other format.

Paste one document, then choose the direction. The parser reports the line that failed when the input is not valid.

Converted document

The output is regenerated from the parsed data, so indentation and quoting follow the target format.

How YAML reads a scalar

Written as Parsed as JSON result
trueBooleantrue
"true"String"true"
42Integer42
42.0Float42
null or ~Nullnull
yesString in YAML 1.2"yes"
2024-05-01Timestamp in many parsersISO date string

Rate this Tool

0.0/5

Based on 0 user ratings.

Same data, two very different syntaxes

JSON optimizes for machines and strict parsing. YAML optimizes for people editing configuration by hand. Converting between them is mostly about knowing what the target format cannot express.

JSON and YAML side by side

JSON uses braces for objects, brackets for arrays, commas between members and double quotes around every key and string. YAML uses indentation for structure, a dash for list items and a colon for key-value pairs. A short document reads almost the same way in both, which hides how different the grammars are underneath.

JSON

{
  "name": "toolburst",
  "version": 2,
  "tags": ["text", "developer"],
  "enabled": true,
  "owner": null
}

YAML

name: toolburst
version: 2
tags:
  - text
  - developer
enabled: true
owner: null
FeatureJSONYAML
StructureBraces and bracketsIndentation and dashes
CommentsNot supported# to end of line
String quotesDouble quotes onlyOptional for plain scalars
Multi-line textEscaped \nBlock scalars with | and >
ReuseNoneAnchors and aliases
Documents per fileOneSeveral, separated by ---
Trailing commasInvalidNot applicable

YAML 1.2 is a superset of JSON, so a valid JSON document is also valid YAML. The reverse is not true, which is the whole reason a converter cannot always be lossless.

How the conversion works

The page does not rewrite text with search and replace. It parses the input into a data structure, then serializes that structure in the other syntax. JSON to YAML runs JSON.parse() followed by jsyaml.dump(). YAML to JSON runs jsyaml.load() followed by JSON.stringify() with two-space indentation.

That two-step path explains both the reliability and the surprises. Because the input is parsed, invalid syntax is caught before anything is emitted, and the output is always well formed. Because the data is re-serialized, formatting, key order nuances and comments from the source are not preserved.

It also means the conversion reflects the parser's type decisions. If a YAML scalar is read as a date, the JSON output contains a date string rather than the original text. Quote the value in YAML when the literal string is what matters.

JSON text { "a": [1, 2], "b": true } Data tree obj array bool YAML text a: - 1 - 2 b: true parse dump Formatting is rebuilt, so the output is valid but not byte-identical to the source.

Mapping values between the two formats

The structural mapping is direct: a JSON object becomes a YAML mapping, a JSON array becomes a YAML sequence, and scalars keep their type. Problems appear at the edges, where one format has a concept the other does not.

JSON valueYAML representationConversion note
ObjectMapping with indented keysNested objects add one indentation level each
ArraySequence of - itemsIndentation of the dash is significant
StringPlain, single-quoted or double-quotedQuoted only when the parser needs it
NumberInteger or floatBoth become JavaScript numbers
Booleantrue or falseYAML also accepts True and TRUE
Nullnull, ~ or emptyAll three parse to null
Escaped newlineBlock scalar | or >Line breaks survive, exact spacing may not

Two practical limits are worth remembering. JSON requires string keys, so a YAML mapping with numeric or boolean keys loses the original key type when converted. And a number larger than 9007199254740991 cannot be represented exactly as a JavaScript number, so long IDs should be quoted strings in both formats.

YAML features that JSON cannot keep

YAML carries information that has no JSON equivalent. A JSON→YAML→JSON round trip is usually safe for the data itself, but a YAML→JSON→YAML round trip often loses presentation details.

  • Comments. A # comment is discarded because JSON has no comment syntax and the parser does not keep it in the data tree.
  • Anchors and aliases. A value defined with &base and reused with *base is expanded into a full copy in JSON. The reuse is not represented.
  • Multiple documents. A stream separated by --- holds several documents. This page converts one document, so split the stream first.
  • Custom tags. Application-specific tags such as !include are not part of the JSON data model and cannot be expressed there.
  • Key order and quoting style. Both are presentation choices. The output places keys in the order the parser returns them and quotes only when required.

If the YAML file is a configuration source that people maintain by hand, keep the original as the source of truth and use the JSON output only for inspection or for a tool that requires JSON.

Indentation, quoting and block scalars

YAML uses spaces for indentation, never tabs. A tab in the leading whitespace is a parse error in the specification, and most parsers reject it immediately. Two spaces per level is the common style; consistency inside one file matters more than the exact count.

A plain scalar needs no quotes, which is why YAML configuration reads cleanly. Quotes become necessary when the text starts with a special character, contains : or #, or would otherwise be read as another type. Quoting "no" or "42" is the standard way to keep them as strings.

literal: | keeps every line break folded: > joins lines into one paragraph quoted: "true" is a string, true is a boolean

Block scalars are the cleanest way to embed a script, a certificate or a paragraph of text. The | style preserves newlines exactly, while > folds single newlines into spaces and keeps blank lines as paragraph breaks.

Common conversion errors

ErrorCauseFix
Tab indentationAn editor inserted a tab instead of spacesConvert leading tabs to spaces
Duplicate keyThe same key appears twice in one mappingKeep one value or rename the keys
Unquoted colon in textA value such as note: see: belowQuote the whole value
Trailing comma in JSONCopied from a JavaScript object literalRemove the comma before the closing brace
Single quotes in JSONJSON only accepts double quotesReplace them or start from YAML
Multiple documentsThe file contains more than one --- blockConvert each document separately
Date shifted by a timezoneAn unquoted date was parsed as a timestampQuote the value to keep it as text

The error message usually includes a line number and a snippet. Start there rather than scanning the whole file; YAML errors cascade because one bad indentation level changes the meaning of everything below it.

Related Developer & Security Tools

Tool What does it do? Action
Base64 Encoder & Decoder Encode text to Base64 or decode a Base64 string back to plain text. Base64 Codec →
Hash Generator Create MD5, SHA-1, SHA-256 and SHA-512 hashes from text. Hash Maker →
UUID Generator Generate random UUID v4 values, one or many at a time. UUID Maker →
Password Generator Build strong random passwords with length and character options. Password Maker →
Regex Tester Test a regular expression against sample text and inspect the matches. Regex Test →
JWT Decoder Decode a JWT header and payload locally, without sending the token anywhere. JWT Decode →

Frequently Asked Questions

In YAML 1.2, yes: a valid JSON document is also valid YAML. That is why JSON can be pasted into the YAML side of a converter without rewriting it. The reverse is not true, because YAML has comments, anchors and block scalars that JSON cannot represent.

No. Comments are not part of the data tree and JSON has no comment syntax. If the comments matter, keep the YAML file as the source of truth and treat the JSON output as a derived artifact.

Numbers are stored as JavaScript floating-point values, which are exact only up to 9007199254740991. Longer integers lose precision. Quote the ID as a string in both formats to keep every digit.

Only in YAML 1.1. Under the YAML 1.2 core schema used by js-yaml 4, yes and no are ordinary strings, while true and false are booleans. Quote them anyway when the value must stay a string across different parsers.

Split the stream at each --- marker and convert the documents one at a time. A JSON document has a single top-level value, so several YAML documents cannot fit into one JSON file without an array wrapper.

No. The parser and the serializer run in the browser. The library itself is fetched from a CDN when the page loads, but the content you paste stays in the tab and is not sent anywhere.