JSON to YAML Converter — Free Online

JSON to YAML Converter

Paste JSON into the left editor and the converted YAML appears on the right. The conversion runs in your browser, and the code path makes no network request with your input.

How this tool converts JSON

The page parses the input with JSON.parse and writes the result with js-yaml 4, using yaml.dump with the indent setting (default 2 spaces). The conversion lives in convertToYaml in src/lib/Lang/v2/json/BaseJsonService.ts, and the JSON to YAML tool uses it through JsonToYamlService.

  • Invalid JSON is never converted. The output pane shows Invalid Json: followed by the parser's message. The wording comes from the browser's JSON parser.
  • Key order follows the input, except keys that look like integers ("1", "2"). JavaScript sorts those first, so they move to the top.
  • Strings are written plain when that is safe. A string that would read back as another type is single-quoted: 'true', '4', 'yes', '2024-01-01', '1e3'.
  • Multi-line strings become | literal blocks. Long single-line strings are folded into >- blocks at about 80 columns.
  • null is written as null. Empty objects and arrays are written as {} and [].
  • Numbers go through JSON.parse first, so integers above 9007199254740991 are rounded before any YAML is written. 1e400 becomes .inf.
  • Duplicate keys do not raise an error. The last value wins. The Validate action reports duplicate keys, but conversion does not.
  • JSON has no comments or dates, so the YAML has none either.
  • Top-level arrays and scalars convert too. [1, "two"] becomes a root sequence, and "hello" becomes hello.

Worked example: a Kubernetes Deployment

Input:

{
  "apiVersion": "apps/v1",
  "kind": "Deployment",
  "metadata": {
    "name": "web",
    "labels": { "app": "web", "tier": "frontend" }
  },
  "spec": {
    "replicas": 3,
    "selector": { "matchLabels": { "app": "web" } },
    "template": {
      "metadata": { "labels": { "app": "web" } },
      "spec": {
        "containers": [
          {
            "name": "web",
            "image": "nginx:1.27",
            "ports": [{ "containerPort": 80 }],
            "env": [
              { "name": "LOG_LEVEL", "value": "info" },
              { "name": "ENABLE_CACHE", "value": "true" },
              { "name": "WORKERS", "value": "4" }
            ],
            "resources": { "limits": { "cpu": "500m", "memory": "256Mi" } }
          }
        ],
        "nodeSelector": {},
        "tolerations": [],
        "terminationGracePeriodSeconds": null
      }
    }
  }
}

Output, exactly as the tool produces it with indent 2:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  labels:
    app: web
    tier: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: web
          image: nginx:1.27
          ports:
            - containerPort: 80
          env:
            - name: LOG_LEVEL
              value: info
            - name: ENABLE_CACHE
              value: 'true'
            - name: WORKERS
              value: '4'
          resources:
            limits:
              cpu: 500m
              memory: 256Mi
      nodeSelector: {}
      tolerations: []
      terminationGracePeriodSeconds: null

The value fields 'true' and '4' stay strings because they are quoted. Kubernetes expects an environment variable value to be a string, so keep those quotes when you edit the output.

Gotchas

1. Large integer IDs lose digits

{"orderId": 12345678901234567890}

becomes

orderId: 12345678901234567000

Store IDs longer than 15 or 16 digits as JSON strings. {"orderId": "12345678901234567890"} converts to orderId: '12345678901234567890' with every digit intact.

2. Duplicate keys collapse silently

{"replicas": 2, "replicas": 3}

becomes replicas: 3. Nothing warns you that the first value was dropped. Run Validate before you convert a hand-edited file.

3. Numeric-looking keys move to the top

{"name": "x", "2": "two", "1": "one"}

becomes

'1': one
'2': two
name: x

Object key order in JavaScript puts integer-like keys first, so the output does not match your input order.

4. Removing the quotes changes the type

The tool writes value: 'true' because the JSON contains the string "true". If you remove the quotes while editing, value: true becomes a boolean. Quote a value again whenever the target schema expects a string.

5. Invalid JSON produces error text in the output pane

{"a": 1,}

The output pane shows Invalid Json: and the parser's message, Expected double-quoted property name in JSON at position 8 (line 1 column 9). That wording comes from V8, which Chrome and Node use. Other browsers word it differently. If you copy the output before fixing the input, you copy the error text.

FAQ

Why are some values wrapped in single quotes?

Those strings would read back as a different type if they were plain. "true", "4", "yes" and "2024-01-01" are strings in your JSON, so the YAML keeps them as strings.

Are the converted numbers exact?

Only up to 9007199254740991 (2^53 minus 1). Larger integers are rounded by JavaScript before the YAML is written. Use JSON strings for identifiers.

Does the output keep my key order?

Yes, except keys that look like integers, which JavaScript sorts first.

Can I change the indent width?

Yes. The indent setting defaults to 2 spaces and is saved in this browser for each tool.

Can the input be a top-level array?

Yes. [1, "two", null, true] becomes a root YAML sequence starting with - 1.