Toolstia / JSON to YAML converter
JSON to YAML and YAML to JSON converter
Configuration files often move between formats: an API returns JSON, but a Kubernetes manifest, a GitHub Actions workflow or a Docker Compose file wants YAML. This converter handles both directions. Paste JSON to receive YAML written with two-space indentation, or paste YAML to receive indented JSON.
If something is wrong, the message points to the place, for example a line and column for YAML problems. The conversion reads data only, so it is a safe way to check a snippet before you commit it. Lines are not folded when writing YAML, so long strings stay on a single line, and key order is kept as given.
Converted in your browser. This reads data only, and never runs any code inside the YAML. Comments in YAML are not kept when converting to JSON.
How it works
- Choose the direction.
- Paste your data, or press Use sample.
- Copy the result or download it.
Why YAML
YAML shows the same data as JSON but with indentation instead of brackets and quotes, which many people find easier to read and edit by hand. It is widely used for settings files.
Indentation matters
YAML uses spaces to show structure, and tabs are not allowed. A common error is mixed or uneven indentation, and the message tells you the line to check.
Safe reading
The converter only reads data. It does not run any code that might be hidden in a YAML file.
What is lost
Comments in YAML are not kept when converting to JSON, because JSON has no comments. Some YAML features, such as anchors, are expanded into plain values.
A nested example in both formats
The JSON {"name":"Ann","age":30,"tags":["a","b"],"address":{"city":"Dhaka"}} becomes YAML with name: Ann and age: 30 on their own lines, tags as a dash list indented by two spaces, and address with city indented beneath it. Nested objects inside arrays use the compact form, where the first key follows the dash, such as - c: 2.
Multi-line strings are written as block scalars. A value of line1, a newline and line2 comes out with a pipe and a minus sign after the key, then each line indented underneath, so readers see the lines as written.
Strings that must stay quoted
The writer adds quotes when a plain string could be read as another type. A version string 1.10 is written as '1.10', because unquoted it would be the number 1.1. The text 007 stays '007' and the word yes is quoted as 'yes', which keeps older YAML parsers from reading it as a boolean. The key on is quoted too, for the same reason.
This is correct behavior, not noise, and it protects values such as zip codes, version numbers and country codes from silently changing type.
How YAML values are read in the other direction
For YAML to JSON, the tool follows the YAML 1.2 style rules. The plain word yes stays the string yes and is not turned into true, while true and false are booleans. Numbers can surprise you: 010 is read as the number 10, 0x1F as 31 and 0o17 as 15, and 1.0 becomes 1 in JSON.
A bare date like 2024-01-15 is read as a timestamp and written in JSON as 2024-01-15T00:00:00.000Z. Quote the date in the YAML if you need to keep it as the exact text.
Anchors, merges and comments
YAML lets you define a block once with an anchor and reuse it, for example base: &b {x: 1} followed by use: with a merge key <<: *b and y: 2. Converting to JSON expands the reference into a plain object with x and y inside use. JSON has no way to point back to something, so the result repeats the data.
Comments disappear when converting YAML to JSON, and converting JSON back to YAML will not bring them back. Keep your original YAML if the comments matter.
Error messages and large numbers
Common YAML mistakes are tabs for indentation, which are reported as not allowed along with the line and column, and a file with several documents separated by three dashes, which is refused because only one document is read. For JSON, the message comes from your browser and usually names the unexpected character, such as a trailing comma.
Because JSON is parsed by the browser, integers beyond about 9 quadrillion lose precision. For example 12345678901234567890 is read and written back as 12345678901234567000. If you must keep long IDs exact, store them as strings before converting.
Questions
Is my data uploaded?
No. It is converted in your browser.
Why does it say the YAML is invalid?
Usually the indentation is uneven, a tab was used, or a colon is missing a space after it. The message shows the line.
Can it handle several YAML documents in one file?
No. Convert one document at a time.
Which YAML version?
The common YAML 1.2 rules used by most tools.
Why did my number with a leading zero change?
In YAML to JSON, a value such as 010 is read as an ordinary number, so it becomes 10. Put quotes around it in the YAML to keep it as text.
Can it convert YAML files with several documents?
No. A file with more than one document gives an error. Convert each document separately.
Will the key order stay the same?
Yes. Keys are written in the order they appear in your input.
Why are some strings in single quotes in the YAML output?
Quotes are added where plain text would be interpreted as a number, boolean or null, or would contain special characters.
Can I choose a different indentation width?
Not here. YAML output uses two spaces and JSON output uses two spaces as well.