How to use YAML to JSON
- Paste the YAML content.
- Pick the indentation and how multiple documents should be handled.
- Copy or download the JSON.
YAML to JSON features
- Parses YAML 1.2 with anchors, aliases, merge keys and block scalars
- Combines multi-document streams into an array or keeps the first document
- Errors reported with line, column and an excerpt
- Dates and binary data converted to JSON-safe strings
- Duplicate keys are rejected instead of silently overwritten
- Choice of indentation or minified output
YAML to JSON example
Convert a CI job definition
Input:
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: npm testOutput:
{
"jobs": {
"test": {
"runs-on": "ubuntu-latest",
"steps": [
{ "run": "npm test" }
]
}
}
}Frequently asked questions about YAML to JSON
Are anchors, aliases and merge keys supported?
Yes. Anchors (&name) and aliases (*name) are resolved into plain values in the JSON output, so the result contains no references.
What happens with multiple documents (---)?
By default all documents in the stream are combined into one JSON array. You can also choose to convert only the first document.
How are dates and binary values converted?
JSON has no date or binary type, so timestamps become ISO 8601 strings and !!binary values become base64 strings.
Why does my YAML fail to parse?
The most common causes are tabs used for indentation, inconsistent indentation, a missing space after a colon, or duplicate keys. The error names the line and column.
Technical notes
Parsing calls the yaml package's parseAllDocuments with strict mode, uniqueKeys and merge enabled: duplicate keys and tab indentation are hard errors with line, column and excerpt, << merge keys are expanded, and unresolved tags such as !foo become warnings while the value stays a string. The default schema is YAML 1.2 core, so yes/no/on/off stay strings and 010 is decimal 10; a %YAML 1.1 directive switches the schema and changes both.
Before JSON.stringify the value is normalised to JSON-safe types: !!timestamp becomes an ISO 8601 string, !!binary a base64 string, !!set a sequence, !!omap a mapping, and .inf/.nan the strings ".inf"/".nan" rather than null. Non-string keys are stringified (a null key becomes ""). Alias expansion is capped at 1,000 per document to stop 'billion laughs' payloads, and integers beyond 2^53 − 1 lose precision because bigint parsing is not enabled.