JSON ↔ YAML Converter
Convert between JSON and YAML, validate the structure and see how each value type is written in the other format.
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 |
|---|---|---|
true | Boolean | true |
"true" | String | "true" |
42 | Integer | 42 |
42.0 | Float | 42 |
null or ~ | Null | null |
yes | String in YAML 1.2 | "yes" |
2024-05-01 | Timestamp in many parsers | ISO date string |
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
| Feature | JSON | YAML |
|---|---|---|
| Structure | Braces and brackets | Indentation and dashes |
| Comments | Not supported | # to end of line |
| String quotes | Double quotes only | Optional for plain scalars |
| Multi-line text | Escaped \n | Block scalars with | and > |
| Reuse | None | Anchors and aliases |
| Documents per file | One | Several, separated by --- |
| Trailing commas | Invalid | Not 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.
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 value | YAML representation | Conversion note |
|---|---|---|
| Object | Mapping with indented keys | Nested objects add one indentation level each |
| Array | Sequence of - items | Indentation of the dash is significant |
| String | Plain, single-quoted or double-quoted | Quoted only when the parser needs it |
| Number | Integer or float | Both become JavaScript numbers |
| Boolean | true or false | YAML also accepts True and TRUE |
| Null | null, ~ or empty | All three parse to null |
| Escaped newline | Block 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
&baseand reused with*baseis 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
!includeare 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
| Error | Cause | Fix |
|---|---|---|
| Tab indentation | An editor inserted a tab instead of spaces | Convert leading tabs to spaces |
| Duplicate key | The same key appears twice in one mapping | Keep one value or rename the keys |
| Unquoted colon in text | A value such as note: see: below | Quote the whole value |
| Trailing comma in JSON | Copied from a JavaScript object literal | Remove the comma before the closing brace |
| Single quotes in JSON | JSON only accepts double quotes | Replace them or start from YAML |
| Multiple documents | The file contains more than one --- block | Convert each document separately |
| Date shifted by a timezone | An unquoted date was parsed as a timestamp | Quote 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
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.--- 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.
Rate this Tool
Based on 0 user ratings.