How to Convert YAML to JSON, Step by Step
Last updated: · 3 min read
YAML is widely used for configuration files in tools such as Docker Compose, Kubernetes manifests and GitHub Actions, yet many APIs and programs only read JSON. The YAML to JSON Converter parses your text with the js-yaml library and returns the result as indented JSON. Because indentation defines the data structure in YAML, a single extra space can change the meaning of the file. When there is an error, the tool shows the line and column where it occurs. The conversion runs in your browser.
Formula
1. Read the text line by line according to YAML 1.2 rules; each indentation level starts a structure (a mapping or a sequence). 2. A line of the form 'key: value' becomes a mapping member, and a line of the form '- value' becomes a sequence item. 3. Resolve scalar values (number, true/false, null, date, string) according to their type. 4. Turn the resulting data structure into JSON text with JSON.stringify. 5. Write the output with two-space indentation; on bad indentation, stop and report the line and column.
This is not a mathematical formula but a parsing and serialising algorithm. The syntax is defined in the YAML 1.2.2 specification, and details depend on the default schema of the js-yaml library. Because the result is JSON, only the types JSON can express survive: strings, numbers, booleans, null, arrays and objects.
What the inputs mean
- YAML
- The YAML text to convert. Copy the contents of your configuration file and paste them in. Indentation must use spaces, because a tab character is not allowed in YAML indentation.
Worked example: Converting a server configuration to JSON
- Input: under server, two-space indented host and ports keys; under ports, a list with 80 and 443; at the end debug: false.
- The server key becomes an object holding host and ports, and ports becomes an array.
- 80 and 443 stay as unquoted numbers, while example.com becomes a string.
- The line debug: false becomes a boolean false member of the outermost object.
Result: The output is a valid JSON object with two levels of indentation: server (host and a ports array) and the debug field.
How to read the result
The most common problem is misaligned indentation, because YAML structure is defined by indentation. The converter also interprets unquoted values: 1.10 is read as the number 1.1. For that reason, put version numbers and identifiers in quotes before converting. Check the result against the rules of the application that will use it. This is general information.
Common mistakes
- Using a tab character for indentation; YAML accepts only spaces there.
- Writing sibling lines with different indentation; this produces a 'bad indentation of a mapping entry' error with the line and column.
- Writing version numbers such as 1.10 without quotes; the value is converted to 1.1.
- Treating dates as text: 2026-11-20 becomes a timestamp in ISO format (2026-11-20T00:00:00.000Z).
- Expecting hexadecimal notation such as 0x1F to stay as written; it becomes the number 31.
Frequently asked questions
Are YAML comments carried over to JSON?
No. Lines starting with # are not data, and JSON has no comment syntax, so they are not included in the output.
Do values such as NO or on become false or true?
Not under the YAML 1.2 rules this tool uses; they stay as text. Older YAML 1.1 parsers treated them as booleans.
Is my file sent to a server during conversion?
No, the conversion runs in your browser. Still, it is good practice to mask secret keys before sharing a file.
Can I convert the JSON back to YAML?
Yes, with the JSON to YAML Converter. Original quoting style and YAML comments do not come back, though.
The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.