JSON to YAML Converter

JSON Input
1
YAML Output

Last updated:

Jsonic's JSON to YAML converter transforms JSON into YAML format with 2-space indentation. It handles all JSON types: strings, numbers, booleans, null, arrays, and nested objects. String values that could be misread as other types are automatically quoted. Paste your JSON and click Convert — the conversion runs entirely in your browser.

How JSON to YAML conversion works

Conversion strips the four structural tokens JSON uses — curly braces, square brackets, commas, and most quotes — and rebuilds the same data tree using indentation. Object keys become indented mappings, so nesting depth is expressed purely by how far a line is pushed right (2 spaces per level here). Nothing about the data changes; only the syntax does.

{
  "server": {
    "host": "localhost",
    "port": 8080,
    "debug": true
  }
}
server:
  host: localhost
  port: 8080
  debug: true

Arrays become dash-prefixed sequences

A JSON array turns into a YAML sequence: each element gets a - prefix at the array's indentation level. For an array of objects, the object's first key sits on the same line as the dash and its remaining keys align underneath — a layout that is much easier to scan than bracket-and-comma JSON.

{
  "plugins": [
    { "name": "auth", "enabled": true },
    { "name": "billing", "enabled": false }
  ]
}
plugins:
  - name: auth
    enabled: true
  - name: billing
    enabled: false

Why some strings stay quoted (type preservation)

In YAML a bare scalar like 1.0, true, or 2026-01-01 is parsed as a number, boolean, or date — not a string. To keep a JSON string a string, the converter quotes any value that would otherwise be coerced. The classic trap is a ZIP code: unquoted 00123 becomes the integer 123 and loses its leading zero. JSON null is written as the YAML tilde ~.

{
  "enabled": true,
  "retries": 3,
  "version": "1.0",
  "zip": "00123",
  "deletedAt": null
}
enabled: true
retries: 3
version: "1.0"
zip: "00123"
deletedAt: ~

Long strings: folded and literal block scalars

JSON crams multi-line text into a single string with \\n escapes, which is hard to read. YAML offers block scalars instead: | (literal) keeps every newline as written, while > (folded) joins wrapped lines into spaces. This is the one case where YAML is genuinely more legible than the JSON it came from.

{
  "script": "echo build\necho test\necho deploy",
  "summary": "A long one-line description that you would rather wrap across several lines for readability."
}
script: |
  echo build
  echo test
  echo deploy
summary: >
  A long one-line description that you would
  rather wrap across several lines for readability.

What gets lost: comments and anchors

The JSON to YAML to JSON round trip is lossless for data but lossy for authored formatting. JSON has no comment syntax, so a converter cannot invent the # comments and &anchor/*alias references a hand-written YAML config might use — and converting such YAML back to JSON silently drops them. Plan to re-add comments and anchors by hand after conversion.

# This comment and the anchor below CANNOT come from JSON
defaults: &defaults
  retries: 3      # inline comment also lost on round trip
prod:
  <<: *defaults
  host: prod.example.com

Convert JSON to YAML in code

When you need conversion in a script or CI pipeline instead of the browser tool:

# Python — PyYAML (pip install pyyaml)
import json, yaml
data = json.loads(json_string)
print(yaml.dump(data, default_flow_style=False, allow_unicode=True))
# default_flow_style=False forces block style; for YAML 1.2 use ruamel.yaml
// Node.js — js-yaml (npm i js-yaml), YAML 1.2 by default in v4+
import yaml from 'js-yaml'
console.log(yaml.dump(JSON.parse(jsonString)))
# Command line — yq, no script needed
yq -P -oy '.' data.json   # -P prettifies, -oy outputs YAML

For a deeper walkthrough see the JSON to YAML tutorial. To convert JSON to a different config format, try JSON to TOML.

How to convert JSON to YAML

  1. Paste your JSON into the left panel.
  2. Click Convert.
  3. YAML output appears with 2-space indentation.
  4. Click Copy or Download to save.

FAQ

Is the YAML output standards-compliant?

Yes. The output follows YAML 1.2 conventions — strings are quoted when necessary, booleans use true/false, and nulls use ~.

How are nested objects converted?

Nested JSON objects become indented YAML mappings. Arrays of objects become YAML sequences with block mapping entries.

Is my data sent to a server?

No. Conversion runs entirely in your browser.

Can I use the YAML output in Kubernetes or Docker configs?

Yes. The output is standard YAML and works in any YAML-consuming tool including Kubernetes manifests, Docker Compose files, and GitHub Actions workflows.

What happens to JSON null values?

JSON null values are represented as ~ in YAML.

How are numbers and booleans handled?

JSON numbers and booleans are preserved as-is in YAML without quotes.

Can I convert YAML back to JSON?

Not in this tool. For the reverse direction, you can manually convert or use a separate YAML-to-JSON tool.