The complete guide

JSON to YAML: the complete guide

The YAML format, the conversion rules, and how YAML behaves in real infrastructure.

Try the Converter

YAML syntax basics

YAML uses three structural markers: indentation for hierarchy, colons for key-value pairs, and dashes for list items. Whitespace is significant — YAML does not use braces or brackets. A simple document:

name: web-server
replicas: 3
image: nginx:1.25
ports:
  - 80
  - 443
labels:
  app: web
  tier: frontend

The indentation (2 spaces per level) creates the hierarchy. A dash followed by a space introduces a list item. A colon followed by a space separates a key from its value. That's the whole syntax — YAML 1.2 is designed to be the most readable structured data format ever standardised.

YAML is also a strict superset of JSON: any valid JSON document is also a valid YAML document. That's what makes the conversion lossless.

How does the conversion work?

JSON has six value types: object, array, string, number, boolean, null. YAML has the same six types, plus extras like timestamps and binary data. The conversion is one-to-one for the shared types, with these rules:

  • Objects become block-style mappings with each key on its own line, indented under the parent.
  • Arrays become block-style sequences with each item prefixed by a dash.
  • Strings stay unquoted unless they contain special characters or look like other types (numbers, booleans, null).
  • Numbers stay as plain digits (no quotes), matching YAML's native number type.
  • Booleans are emitted as true or false (lowercase, the YAML 1.2 canonical form).
  • Null is emitted as null or ~ (both are valid YAML).

JSON keys are always strings, so they become unquoted YAML keys (the standard practice). If a key would be ambiguous (e.g., contains a colon or starts with a number), the converter adds quotes automatically.

When does YAML need quotes?

YAML is permissive about quoting but strict about ambiguity. A string that could be parsed as a number, boolean, or null must be quoted to be treated as a string. Examples:

  • version: 1.0 — parsed as a number unless quoted ("1.0")
  • active: true — parsed as a boolean unless quoted ("true")
  • empty: null — parsed as null unless quoted
  • on: yes — parsed as boolean true (YAML 1.1 compatibility)
  • code: 01234 — parsed as octal in some parsers; quote to be safe

Strings that contain special characters (colons, hashes, leading/trailing whitespace, newlines, leading dashes) also need quoting. The converter applies quoting automatically using these rules. Toggle "Quote all strings" in settings if you want every string to be quoted explicitly — useful for diff stability and for users unfamiliar with YAML's ambiguity rules.

Multi-line strings

JSON has no real multi-line string type — embedded newlines must be escaped as \n. YAML supports two block scalar styles:

  • Literal (|): Newlines are preserved exactly. Best for code, configuration blobs, and any text where formatting matters.
  • Folded (>): Newlines become spaces, except for blank lines which become single newlines. Best for prose where you'd otherwise use one long line.

When converting JSON, the converter can't know which style you want (the JSON doesn't encode the difference), so it defaults to literal (|) for any string containing a newline. You can change the default in settings or by post-processing the file.

Anchors and aliases

YAML has a feature JSON lacks: anchors (&name) and aliases (*name). An anchor marks a value for reuse; an alias refers back to it. This is useful for DRY configurations:

defaults: &defaults
  retries: 3
  timeout: 30
production:
  <<: *defaults
  host: prod.example.com
staging:
  <<: *defaults
  host: staging.example.com

JSON has no equivalent, so converting a YAML file with anchors to JSON will inline the values (losing the DRY structure). Converting JSON to YAML can't create anchors automatically — the input has no concept of "this is the same as that." If you need anchors, add them by hand after the conversion.

Kubernetes conventions

Kubernetes uses YAML 1.2 with a few conventions worth knowing:

  • 2-space indent. Always. Tools like kubectl apply and helm install don't care, but humans reading the file do.
  • Lowercase keys. apiVersion, kind, metadata, spec. The schema is case-sensitive.
  • apiVersion first, then kind, then metadata, then spec, then status. Most YAML sorters will reorder keys to this convention; if yours doesn't, do it by hand.
  • Strings with template syntax ({{ .Values.foo }}) should be quoted to avoid YAML's type-coercion rules interpreting .Values.foo as a number.
  • Multi-document YAML (multiple ----separated documents in one file) is common for k8s manifests. The converter doesn't split or merge these — one JSON document becomes one YAML document.

Common edge cases

Most JSON-to-YAML conversions are straightforward, but a few patterns are worth knowing about:

  • Empty objects and arrays: Emitted as {} and [] (flow style). This is the most portable representation across parsers.
  • Empty strings: Emitted as "" (quoted) to distinguish them from null and to make the column width obvious in editors.
  • Unicode: Preserved as-is. YAML is UTF-8 by default, so emoji and non-Latin characters round-trip cleanly.
  • Very long strings: The converter doesn't wrap them. If you need a hard wrap, post-process the output (or use YAML's folded scalar style).
  • Numbers that look like dates: 20241231 stays a number. "2024-12-31" stays a string. YAML 1.2 doesn't auto-parse dates (that's a YAML 1.1 quirk).
  • Trailing whitespace in strings: Preserved. YAML parsers handle this correctly; some text editors may strip it on save.
FAQ

Frequently asked questions

What is a JSON to YAML converter?
A JSON to YAML converter takes a JSON document and produces an equivalent YAML file. JSON and YAML are designed to be interchangeable: both represent the same data structures with different syntax. YAML is preferred for configuration files because it's more human-readable and supports comments.
Is JSON to YAML conversion free?
Yes. HopConvert's JSON to YAML converter is 100% free with no sign-up required. There are no paid tiers, no feature gates, and no premium plans. Conversion runs in your browser so we don't pay for servers and we don't charge you.
What is YAML used for?
YAML is the standard format for configuration files in modern infrastructure and deployment tools: Kubernetes manifests, Docker Compose files, Ansible playbooks, GitHub Actions workflows, GitLab CI pipelines, Prometheus alert rules, Helm charts, and many more. It's also used for data serialization and cross-language data exchange.
Is YAML 1.2 supported?
Yes. The converter produces YAML 1.2 output, which is the current standard. YAML 1.2 is a strict superset of JSON, so any valid JSON document is also valid YAML.
Can I convert a Kubernetes manifest JSON to YAML?
Yes. kubectl can output any resource as JSON; paste that into the converter and you'll get a clean YAML manifest ready to commit to a Git repo. The output uses 2-space indent, which is the Kubernetes convention.

Try the JSON to YAML converter

Free, instant, and private — your JSON never leaves this tab.

Open the JSON to YAML Converter