Skip to content
FmtTools

JSON to YAML Converter

Emit block-style YAML that a YAML 1.2 reader parses back to the same value — and, more importantly, that a YAML 1.1 reader does not misread as booleans, versions or sexagesimal numbers.

Indentation

Null style

Line ending

YAML 1.1 defence

Values that a 1.1 reader would retype are quoted automatically; the list is below.

JSON input

Bytes 553Parses yes

YAML output

# converted from JSON by FmtTools — YAML 1.2 safe output
apiVersion: apps/v1
kind: Deployment
metadata:
  name: orders-api
  labels:
    app: orders
spec:
  replicas: 3
  template:
    spec:
      containers:
        - name: api
          image: registry.local/orders:1.10
          env:
            - name: DEBUG
              value: 'NO'
            - name: PORT
              value: '8080'
        - name: worker
          image: registry.local/worker:2.0
          args:
            - '--retry'
            - '12:30'
notes:
|-
  Two lines:
  second line becomes a block scalar.
Bytes 584Lines 29Protected 3

3 value(s) quoted to stop a YAML 1.1 reader retyping them

Each of these is a string in your JSON. Written as a bare scalar it would resolve to a boolean, a number, a null or a different float depending on which edition of the specification the parser implements.

  • "NO"Quoted so a YAML 1.1 reader does not resolve it to boolean (false).
  • "8080"Quoted so it stays a string instead of becoming a number and losing formatting such as a leading zero or a trailing .0.
  • "12:30"Quoted so a YAML 1.1 reader does not resolve it to integer (base 60) (750).
Output bytes
584
Input bytes
553
Lines
29
Longest line
56
Protected values
3

Quoted against 1.1 coercion

Unrepresentable
0
Block scalars
enabled
Indentation
2 spaces

Safe output means quoting things a human would not suspect

JSON has strings and numbers; YAML decides what a bare scalar is. NO is a boolean in YAML 1.1 and a string in 1.2, 1.10 is a float that prints as 1.1, 017 is octal under one spec and a string under another, and 12:30 was sexagesimal 750 in YAML 1.1. Emitting a bare scalar for any of those is how a country code becomes false in a Kubernetes manifest.

This writer tests every string against the resolver tables from both spec editions and quotes the ones where they disagree, then reports each protected value so you can see the decision. Multi-line strings become block scalars with an explicit chomping indicator rather than a quoted string full of \n, which keeps a chart template or a README readable in review.

Output is valid YAML 1.2 and deliberately unexciting: no anchors, no custom tags, no flow style except where a value is genuinely a flow collection, because configuration that needs cleverness is configuration that fails in a pipeline.

What the YAML writer controls

  • Block style with 2, 3 or 4 space indentation
  • YAML 1.1 and 1.2 safe scalar quoting decisions
  • Block scalars for values containing newlines
  • Explicit null representation: null, ~ or empty
  • Numbers emitted so no reader retypes them
  • Optional alphabetical key sorting for diff stability
  • Document start marker and header comment for manifests
  • LF or CRLF line endings
  • Report of every value it chose to quote and why
  • Round-trip check against the parsed JSON input

How to convert JSON to YAML

  1. 1Paste the JSONA manifest, a values file or an API response all work. If the input will not parse, fix it with the JSON validator first; this tool will not guess at malformed input.
  2. 2Choose indentation to match the target projectTwo spaces is the Kubernetes and Docker Compose convention. Three or four is legal YAML but produces longer diffs and trips linters configured for the ecosystem default.
  3. 3Decide the null stylenull is unambiguous in every reader. ~ is idiomatic but invisible in a scan; the empty form is the one that creates accidental nulls when someone deletes a value and leaves the key.
  4. 4Review the protected values listAnything quoted that you would have expected bare was quoted deliberately: it is a value a YAML 1.1 parser — including older PyYAML and some Go libraries — would have retyped.

Scalars the writer quotes rather than emit bare

JSON string values, and what each would become if written without quotes.
ValueBare outputUnder YAML 1.1Under YAML 1.2 core
"NO"NOboolean falsestring
"on"onboolean truestring
"1.10"1.10float 1.1float 1.1
"017"017integer 15 (octal)string
"12:30"12:30integer 750string
"2025-01-07"2025-01-07timestamptimestamp
"y"yboolean truestring
"~"~nullstring

Quoting costs three characters. Each of these rows has been an outage in someone’s pipeline; the default is to quote all of them.

Frequently asked questions

Why are my strings quoted in the YAML output?

Because bare scalars are typed by the reader, not the writer. The table above shows the cases: NO, on, 1.10, 017, 12:30 and date-like strings all resolve to something other than a string in at least one widely deployed parser. Quoting is the only portable spelling.

Does the output keep JSON comments?

No — JSON has no comments (see RFC 8259 §3), so a document with them is JSON5 or a config dialect and must be repaired first. YAML comments, going the other way, are destroyed by conversion because the data model has nowhere to put them.

Can it produce Kubernetes-ready manifests?

It produces the YAML that a data block converts to, with a document marker and two-space indentation as options. Field ordering, apiVersion correctness and schema validation remain yours — run kubectl --dry-run=server -f or kubeconform against the result.

What happens to very long strings?

Values containing newlines become block scalars with an explicit chomping indicator, which keeps a script or template readable. Long single-line values are not wrapped, because folding a scalar at a column width can alter trailing spaces inside the value.

Does YAML support the full JSON range?

The JSON schema of YAML 1.2 does, by design — JSON is a subset of YAML 1.2 (§6 of the spec, "JSON: YAML's Second Data Format"). What does not survive is NaN and Infinity, which are valid YAML floats but not JSON numbers, and those are reported as unrepresentable.

Should config be YAML or JSON?

Depends on who reads it. See YAML vs JSON for the failure modes each format produces in review, and YAML vs TOML if the reason you are asking is indentation.

Why trust this emitter with a manifest that has to deploy?

Because it treats an unquoted value as a decision rather than a default. Anything a YAML 1.1 reader could retype — NO, on, Off, ~, 1.10, a sexagesimal look-alike, a date-shaped string — comes out quoted; non-finite numbers are reported as having no number form in the core schema instead of silently becoming null; multi-line text becomes a block scalar rather than one escaped line; and indentation is consistent spaces, which is the one thing YAML never forgives.