ITInfoByte

How to convert JSON to YAML without breaking your config

By Amirtham ·

Open JSON ⇄ YAML Converter →

Every JSON document is already valid YAML 1.2, so conversion is really about producing the readable YAML style — indentation instead of braces — while making sure no value silently changes type on the way.

A worked example

This JSON describes a service configuration:

{
  "service": "checkout", "replicas": 3, "debug": false,
  "country": "no", "enabled": "yes", "version": "1.10", "zip": "01234",
  "tags": ["web", "payments"],
  "env": { "LOG_LEVEL": "info", "TIMEOUT_MS": 2500 },
  "notes": null
}

The JSON ⇄ YAML converter (built on the js-yaml library) produces:

service: checkout
replicas: 3
debug: false
country: 'no'
enabled: 'yes'
version: '1.10'
zip: '01234'
tags:
  - web
  - payments
env:
  LOG_LEVEL: info
  TIMEOUT_MS: 2500
notes: null

Why some values are quoted

Look at 'no', 'yes', '1.10' and '01234'. Unquoted, a YAML parser could read them as something other than the strings they are in the JSON:

  • no and yes are booleans in YAML 1.1, which many tools still use. This is the famous "Norway problem": a country code NO turning into false.
  • 1.10 unquoted is the number 1.1 — a version string would lose its trailing zero.
  • 01234 could be read as a number (and by some parsers as octal), losing the leading zero of a postal code.

The converter quotes these automatically. If you edit YAML by hand, quote any string that looks like a number, a date, a boolean or null.

Going the other way: YAML to JSON

Paste YAML and choose YAML → JSON. A few YAML features have no JSON equivalent and are resolved or dropped:

  • Comments are discarded — JSON has none.
  • Anchors and aliases (&defaults / *defaults) are expanded into full copies.
  • Custom tags such as !Ref in CloudFormation templates aren't understood by the safe loader and produce an error rather than a guess.

So a YAML → JSON → YAML round trip gives equivalent data, not an identical file. Keep the YAML as the source of truth if it has comments you care about.

Questions

Is my configuration uploaded?

No. The conversion runs in your browser; the js-yaml library is downloaded once from cdnjs and your data stays on your device.

Which YAML version does it use?

Parsing follows YAML 1.2 via js-yaml's safe loader; output quotes values that YAML 1.1 parsers would misread.

Tools used in this guide