JSON to YAML

Paste or upload JSON to convert it into carefully quoted YAML. Runs in your browser.

Pasted text and chosen files stay on this device. Nothing is sent to a server.

Drop a file here, choose one, or paste.

No output yet Convert to see the result here.

How to use it

  1. 1

    Paste the JSON.

  2. 2

    Read the quoted-scalar list: those are the strings that would have changed meaning.

What it does

JSON has one kind of string and one way to write it. YAML does not: a plain scalar is interpreted, so converting naively turns some strings into booleans and dates. That is the whole difficulty.

Walk the JSON value and emit YAML, quoting any scalar that YAML would resolve as a non-string. Report which scalars had to be quoted and why.

Why it works this way

YAML 1.1 resolves yes, no, on, off, y and n as booleans. A JSON string "yes" written bare becomes true, so it is quoted and the report names it.

Version numbers and dates are the other two: 1.10 becomes the number 1.1, and a date-like string becomes a date. Neither is visible in the YAML if you only look at it.

The value is unchanged. Anything the conversion cannot express is reported rather than approximated, because a config file that silently changed a value is worse than one that failed.

Examples

{"flag": "yes"}
flag: "yes"
bare yes would be the boolean true in YAML 1.1
{"v": "1.10"}
v: "1.10"
bare 1.10 is the number 1.1 and the trailing zero is gone

Inputs and outputs

  • JSON text
  • indent
  • quote policy: only when needed / always
  • YAML text
  • the scalars that were quoted to stay strings

Edge cases

  • strings that look like booleans, numbers, dates and null
  • multi-line strings — literal block or quoted
  • keys containing colons
  • deeply nested arrays of objects
  • very long documents

Frequently asked questions

Why is my string quoted?

Because YAML would read the bare form as a boolean, a number, a date or null. The report names every one.

Is the value changed?

No. Quoting preserves the string exactly; the alternative would have changed it.

Related tools

Sources

  • YAML 1.2 specification, section 10.2 (Scalar resolution)