# JSON ↔ YAML Converter

> Convert JSON to block-style YAML or YAML back to JSON, entirely in your browser. Parse errors point to the exact line and column, and conversion notes flag the lossy edges like dropped comments and expanded anchors.

- Tool: https://ronutz.com/en/tools/json-yaml-convert
- Family: Encoding & data

---

## What it does

Convert a document between JSON and YAML in either direction, in your browser. Going from JSON it produces block-style YAML; going from YAML it produces JSON. When a parse fails, the error names the exact line and column, and when a conversion loses something along the way, a note explains what and why.

## The two directions

- **JSON to YAML.** The JSON is first validated by the same precise, position-tracking parser the JSON formatter uses, so an invalid document is rejected with a line, column, and JSON Pointer path rather than a vague failure. The valid data is then written as block-style YAML.
- **YAML to JSON.** The YAML is parsed under a JSON-compatible schema and serialized to JSON. Anchors and aliases (YAML's `&name` and `*name` reuse mechanism) are expanded inline, and block scalars (YAML's multi-line string styles) become ordinary JSON strings.

## The quoting traps it handles

YAML is famously willing to read a bare word as something other than a string, which is where round-trips go wrong. The best-known case is the "Norway problem": the bare word `NO` is read as the boolean false, and the same happens to `yes`, `on`, and `off`, and to values like `1.0` (a number, not the string "1.0") and `08` (which is not valid octal). When emitting YAML, the converter quotes these values so that what you meant as a string survives as a string.

## What conversion can lose

Some things exist in one format but not the other, so the notes flag them:

- **Comments.** YAML has comments and JSON does not, so comments are dropped when converting YAML to JSON.
- **Anchors and aliases.** These are expanded to their full value, so a compact shared reference in the source YAML becomes repeated data in the output.

## Worked examples

- JSON `{"port":8080,"tls":true}` becomes the YAML lines `port: 8080` and `tls: true`.
- YAML `country: NO` becomes JSON `{"country":"NO"}` on the way in, and when that is emitted back to YAML the value is quoted as `country: "NO"` so it is not mistaken for false.

## Using it

Paste JSON to get YAML, or YAML to get JSON. Read the conversion notes when they appear: they tell you whether anything, such as a comment or an anchor, changed in a way you should be aware of. The conversion is deterministic for a given input.

## Standards and references

- [YAML Ain't Markup Language (YAML) 1.2.2 Specification](https://yaml.org/spec/1.2.2/) - the YAML data model, its relationship to JSON, and core/JSON schemas
- [RFC 8259 - The JavaScript Object Notation (JSON) Data Interchange Format](https://www.rfc-editor.org/rfc/rfc8259) - the JSON side of the conversion
- [js-yaml - YAML parser and serializer for JavaScript](https://github.com/nodeca/js-yaml) - the YAML parser and emitter, used under the JSON-compatible schema

## Related reading

- [JSON and YAML in Practice: APIs, Declarations, and Orchestration](https://ronutz.com/en/learn/config-formats-in-practice.md): The split is not random: APIs and machine-to-machine declarations tend to be JSON, while human-authored orchestration and pipeline files tend to be YAML. Understanding why each domain chose what it did explains when converting between them is useful.
- [JSON vs YAML: What Converts Cleanly and What Does Not](https://ronutz.com/en/learn/json-vs-yaml.md): YAML was designed so that every JSON document is also valid YAML, which is why conversion between them usually just works. The interesting part is the edges: comments, anchors, multiple documents, and YAML-only types that have no JSON equivalent.
- [YAML Anchors, Aliases, and Merge Keys](https://ronutz.com/en/learn/yaml-anchors-and-aliases.md): YAML can define a value once and reuse it with an anchor and alias, and merge one mapping into another with a merge key. None of this exists in JSON, so converting expands and duplicates it. This covers the syntax, what happens on conversion, and the denial-of-service trap they enable.
- [YAML Block Scalars and Multiline Strings](https://ronutz.com/en/learn/yaml-block-scalars.md): YAML has two ways to write a multiline string, and they treat newlines differently: literal style keeps them, folded style turns them into spaces. Chomping indicators then decide what happens to the trailing newline. Getting these wrong is why an embedded script or certificate comes out subtly mangled.
- [YAML Type Coercion and the Norway Problem](https://ronutz.com/en/learn/yaml-type-coercion.md): YAML guesses the type of every unquoted scalar, and its guesses are surprising: the country code NO becomes false, a version like 1.0 becomes a number, and a zero-padded code loses its zeros. Knowing the rule is the key to safe conversion.
