OnSumoTools

JSON to YAML Converter

This tool converts JSON to YAML and YAML to JSON in one click. Paste your JSON or YAML into the input, select the target format, and the tool returns the converted output with correct indentation and syntax. Conversion happens entirely in your browser. Your data never leaves your device, which matters when you are working with API keys, database credentials, Kubernetes secrets, or any configuration that should not pass through an external server.

Direction

YAML anchors are resolved when converting to JSON. JSON does not support comments or anchors.

YAML output

Input: 0 chars

How does the JSON to YAML Converter work step by step?

The JSON-YAML converter bidirectionally transforms JSON and YAML while preserving the semantic structure of the data. JSON-to-YAML conversion replaces braces and brackets with indentation and dashes, strips explicit quotes from string keys where not required, and uses bare null or the tilde (~) for null values per the YAML 1.2 spec. YAML-to-JSON conversion serializes scalar types with careful handling of YAML's boolean ambiguity: unquoted yes, no, on, and off are booleans in YAML 1.1 (used by PyYAML and Ruby's default YAML) but plain strings in YAML 1.2. The tool defaults to YAML 1.2 behavior with a toggle to YAML 1.1 coercion for compatibility with legacy parsers. YAML anchors and aliases are fully resolved to their referenced values before conversion, since JSON has no equivalent reference mechanism. Key assumption: the tool processes single-document YAML; multi-document streams (separated by ---) convert each document independently to a JSON value and wrap the results in a JSON array. Edge case: YAML allows inline comments but JSON does not. Comments are stripped silently during YAML-to-JSON conversion and cannot be round-tripped back to YAML. If your YAML file relies on comments for documentation, maintain the YAML source separately alongside the JSON export.

What does a typical JSON to YAML Converter result look like?

{"name": "John", "age": 30} becomes YAML with name and age keys. A YAML literal block (|) becomes a JSON string with newline characters. {"key": null} round-trips as null, not the string "null".

Related tools

Frequently asked questions

  • Is YAML a superset of JSON?

    Yes, in most cases. Valid JSON is also valid YAML 1.2. This means you can paste a JSON string directly into a YAML parser and it will parse correctly. However, JSON's handling of numbers with leading zeros and some edge cases differ between implementations, so the tool uses explicit conversion rather than relying on YAML's JSON compatibility mode.

  • What happens to YAML comments when converting to JSON?

    They are discarded. JSON has no comment syntax. If you convert YAML-with-comments to JSON and back to YAML, the comments will be gone. If you need to preserve comments, keep the canonical version as YAML and generate JSON from it programmatically, treating JSON as the derived format.

  • What are YAML anchors and aliases, and how are they handled?

    Anchors (&anchor-name) and aliases (*anchor-name) are a YAML feature for reusing values. An alias in YAML is a reference to a previously defined anchor. When converting to JSON, the tool resolves aliases and inlines the referenced value at each usage site. JSON has no reference mechanism, so each value must be spelled out.

  • Does the tool support YAML 1.1 vs YAML 1.2 differences?

    The tool uses a YAML 1.2 parser, which is the current standard. YAML 1.1 had quirks like interpreting yes/no/on/off as booleans. YAML 1.2 only treats true and false as booleans. If you have YAML 1.1 content that uses yes or no as booleans, the tool may treat them as strings.

  • Why does my number `007` become `7` in JSON?

    JSON numbers do not allow leading zeros (they would be interpreted as octal in some parsers). When YAML containing 007 is converted to JSON, the leading zeros are stripped to produce a valid JSON number. If 007 is intended as a string, quote it in the YAML source: \\\\\\\"007\\\\\\\".

  • Can I use this for converting package.json to YAML?

    Yes. Any JSON can be converted to YAML. However, package.json is expected to be JSON by npm and all Node.js tooling. Converting it to YAML would require renaming it and adding a tool that can read YAML package files. The conversion is technically possible but not recommended without a toolchain that supports YAML package configuration.

JSON and YAML, side by side

Both formats describe the same kind of data: objects, lists, strings, numbers, booleans and nulls. JSON uses braces and quotes. YAML uses indentation and reads more like an outline. Config files for Kubernetes, GitHub Actions and Docker Compose lean on YAML. APIs lean on JSON.

So you end up converting back and forth all the time. This tool does it in both directions, checks the input as it goes and lets you set the indent.

Valid JSON is valid YAML

Mostly, yes. YAML 1.2 was designed so that JSON is a subset of it, and a YAML parser can read a JSON document. The reverse isn't true. YAML has comments, anchors and multiline strings that JSON simply can't hold.

What gets lost going to JSON

Comments disappear. JSON has no way to store them, so any note in your YAML is dropped when you convert. Keep the YAML as your source file if the comments matter.

Anchors and aliases are YAML's way of reusing a block. An anchor marks a chunk, and an alias points back to it. JSON has no such thing, so the tool resolves them and writes out the full repeated content. The result is longer but equal in meaning.

The 007 problem

A value like 007 can surprise you. In YAML 1.2 it can be read as a number, and as JSON it comes out as 7, with the leading zeros gone. If it's an ID or a ZIP code, wrap it in quotes in the YAML so it stays a string.

Other classic traps include the word no being read as false in some older YAML versions, and times like 12:30 turning into numbers. Quote anything that must stay text.

  • Quote ZIP codes, phone numbers and version strings
  • Quote the words yes, no, on and off if you mean them as text
  • Check the output before committing it

Converting package.json and other config files

You can convert a package.json to YAML if a tool wants it that way. The structure carries over cleanly. Keep in mind that most tools expect package.json to stay JSON, so convert for reading or for another system and not as a replacement.

Everything runs in your browser, and nothing you paste is sent away. Config files often contain secrets, so that's a relief, but remove them anyway before sharing the output.