How to convert YAML to JSON
- Paste your YAML into the Your YAML box, or open a
.yamlor.ymlfile. - Choose the indentation, or Minified for a single line.
- Read the JSON in the result box. Select Copy or Download to save
data.json.
If the YAML is not valid, you see the problem with its line and column instead. A common cause is a mix of tabs and spaces, or a list item that is not lined up with its siblings.
What the converter does
YAML describes the same kinds of data as JSON: mappings (objects), sequences (arrays), strings, numbers, booleans and null. The converter reads your YAML with the safe loader, then writes the same data as JSON.
- Anchors (
&name) and aliases (*name) are expanded into full copies. - Several documents in one file, separated by
---, become a JSON array. - Comments and formatting are dropped, because JSON cannot store them.
- Values such as
yesandonare read as text, not as booleans, following the YAML 1.2 rules. - Dates stay as the text you wrote.
Because the loader is safe, a tag such as !!js/function is rejected with an error rather than being run.
Why convert YAML to JSON
Many APIs, validators and JavaScript tools accept only JSON, while people prefer to write configuration in YAML. Converting lets you test a config against a schema, send it in a request body, or load it in code without a YAML library.
Tips
- Validate the output with the JSON validator before sending it to an API.
- Turn it back into YAML with JSON to YAML.
- Quote values that must stay text, such as version numbers like
"1.10", which would otherwise become the number 1.1. - Empty YAML, or a file with only comments, gives an empty result rather than an error.
Privacy
Kubernetes files, CI configs and app settings often hold secrets. This tool runs only in your browser. Nothing is uploaded, stored or logged.