S SCHEMA.BIZ

Last updated:

JSON to YAML Converter

Paste JSON or open a file and this JSON to YAML converter writes block-style YAML as you type, in your browser, quoting strings like "no" that YAML 1.1 parsers misread.

Options

What changed on the way

  • 2 strings are quoted so that YAML 1.1 parsers read them as text, not as a boolean, number or date (the "Norway problem").
  • Line 7: "NO" is quoted in the YAML: without quotes, a YAML 1.1 parser would read it as false.
  • Line 8: "off" is quoted in the YAML: without quotes, a YAML 1.1 parser would read it as false.
  • The top-level array became 2 YAML documents, separated by ---.

From JSON to readable YAML

JSON to YAML is the direction people take when a config should be edited by hand: a Kubernetes manifest pulled from the API, an OpenAPI spec exported by a framework, a CI workflow generated by a script. Because JSON is already valid YAML 1.2, any JSON file could be renamed to .yaml and still parse. What a converter adds is the YAML people expect to read: no braces, no commas, one key per line, nesting shown by indentation, and quotes only where they're needed.

This converter reads the JSON with the same YAML parser that writes the output, so nothing is lost on the way through JavaScript numbers or objects. Keys keep their order, numbers keep their written form, and integers beyond 253 keep every digit. Maps and lists are written in block style, with empty ones left as {} and [], and multi-line strings become literal blocks (|), which keep each line as it was. Indentation is 2 or 4 spaces; YAML doesn't allow tabs for indentation.

What to watch for when you write YAML

Strings that a YAML parser would retype

The biggest risk in JSON to YAML conversion is a string that loses its quotes and becomes something else. "true" without quotes is a boolean, "8080" a number, and "null" nothing at all. Any careful converter quotes those. The harder cases are strings that are only special in YAML 1.1, the version many parsers still implement: no, off and y are booleans there, 0755 is an octal number, 2222:22 a base-60 number, and 2026-03-14 a date. A converter that writes YAML 1.2 can legally leave them unquoted, and the file then means something different to PyYAML than to the tool that wrote it. This converter quotes them and lists each one under the editors.

Keys are strings too

The same rule applies to keys. GitHub Actions workflows start with on:, which GitHub reads as the word, but a YAML 1.1 parser reads it as true; written as "on":, the key means the same everywhere. Keys made of digits, such as HTTP status codes in an OpenAPI spec, are quoted so they stay strings rather than turning into integers.

No anchors, no comments

YAML can name a value with an anchor and repeat it with an alias, and it can hold comments. JSON has neither, so a converted file has no anchors and no comments: repeated blocks stay repeated. That's the faithful result, since an anchor would be a guess about which copies are meant to stay the same. Once the YAML is in your editor, you can factor repeated settings into an anchor yourself and add comments where they help.

One document or many

A YAML file can hold several documents separated by ---, and Kubernetes tools read such a file as several objects. JSON has one value per file, so tools that export many objects as JSON either wrap them in a List object or print an array. Turn on "Top-level array as separate documents" and each item of the array becomes its own YAML document, ready for kubectl apply -f.

Style choices that don't change the data

Some differences between YAML files are style, not meaning. This converter indents list items two spaces under their key; some tools, kubectl among them, write the - of each item flush with the key, and every parser reads both the same way. Long strings stay on one line rather than being folded at 80 characters, so a long description or a base64 value can be searched for and copied whole. Strings get quotes only when they need them: double quotes, or single quotes when the string itself holds double quotes. If your project has a formatter such as Prettier with its YAML support, run it on the result to match the rest of the repository.

Examples

Each example below shows the JSON and the YAML the converter makes from it. Its link opens the JSON in the converter above, with the options it needs.

Kubernetes manifests from kubectl: an array split into documents

The array holds a ConfigMap and a Service. With documents on, they become two YAML documents. The ConfigMap's values are all strings, as Kubernetes requires for ConfigMap data: "4" is quoted because it looks like a number, and "NO" and "off" because a YAML 1.1 parser would read them as false.

[
  {
    "apiVersion": "v1",
    "kind": "ConfigMap",
    "metadata": { "name": "web-config" },
    "data": {
      "COUNTRY": "NO",
      "DEBUG": "off",
      "WORKERS": "4"
    }
  },
  {
    "apiVersion": "v1",
    "kind": "Service",
    "metadata": { "name": "web" },
    "spec": {
      "selector": { "app": "web" },
      "ports": [{ "port": 80, "targetPort": 8080 }]
    }
  }
]
apiVersion: v1
kind: ConfigMap
metadata:
  name: web-config
data:
  COUNTRY: "NO"
  DEBUG: "off"
  WORKERS: "4"
---
apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  selector:
    app: web
  ports:
    - port: 80
      targetPort: 8080

Open the Kubernetes example in the converter

GitHub Actions workflow: the on key

The workflow's on key comes out quoted, and so does the NOTIFY value yes, for the same YAML 1.1 reason. The cron schedule is a plain string: its asterisks are inside the value, where YAML doesn't treat them as aliases. The empty workflow_dispatch trigger stays {}, which is how GitHub expects a trigger without settings.

{
  "name": "Nightly",
  "on": {
    "schedule": [{ "cron": "30 5 * * 1-5" }],
    "workflow_dispatch": {}
  },
  "jobs": {
    "report": {
      "runs-on": "ubuntu-latest",
      "steps": [
        { "uses": "actions/checkout@v4" },
        { "run": "npm run report", "env": { "NOTIFY": "yes" } }
      ]
    }
  }
}
name: Nightly
"on":
  schedule:
    - cron: 30 5 * * 1-5
  workflow_dispatch: {}
jobs:
  report:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm run report
        env:
          NOTIFY: "yes"

Open the GitHub Actions example in the converter

docker-compose file: repeated settings and port mappings

Both services carry the same logging block, and the YAML repeats it rather than inventing an anchor. Of the two port mappings, 8080:80 is left plain, because 80 can't be a base-60 digit, while "2222:22" is quoted: a YAML 1.1 parser would read it as the number 133342. Docker's documentation recommends quoting every port mapping for this reason.

{
  "services": {
    "app": {
      "image": "example/app:2.1",
      "ports": ["8080:80", "2222:22"],
      "logging": { "driver": "json-file", "options": { "max-size": "10m" } }
    },
    "worker": {
      "image": "example/worker:2.1",
      "logging": { "driver": "json-file", "options": { "max-size": "10m" } }
    }
  }
}
services:
  app:
    image: example/app:2.1
    ports:
      - 8080:80
      - "2222:22"
    logging:
      driver: json-file
      options:
        max-size: 10m
  worker:
    image: example/worker:2.1
    logging:
      driver: json-file
      options:
        max-size: 10m

Open the docker-compose example in the converter

OpenAPI 3.1 spec: dates, versions and big IDs

The spec's version is the string "1.0", so it's quoted; unquoted, YAML would read the number 1. The example date is quoted so YAML 1.1 parsers don't make it a timestamp, and the response code "200" stays a string key, as the OpenAPI specification asks. The example ID, 9007199254740993, is one more than the largest integer JavaScript stores exactly; the YAML keeps every digit, where a converter built on JSON.parse would write 9007199254740992.

{
  "openapi": "3.1.0",
  "info": { "title": "Orders API", "version": "1.0" },
  "paths": {
    "/orders": {
      "get": {
        "summary": "List orders",
        "responses": { "200": { "description": "A page of orders" } }
      }
    }
  },
  "components": {
    "schemas": {
      "Order": {
        "type": "object",
        "properties": {
          "id": { "type": "integer", "format": "int64", "example": 9007199254740993 },
          "placed": { "type": "string", "format": "date", "example": "2026-03-14" }
        }
      }
    }
  }
}
openapi: 3.1.0
info:
  title: Orders API
  version: "1.0"
paths:
  /orders:
    get:
      summary: List orders
      responses:
        "200":
          description: A page of orders
components:
  schemas:
    Order:
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 9007199254740993
        placed:
          type: string
          format: date
          example: "2026-03-14"

Open the OpenAPI example in the converter

Checking the result

A quick way to trust a conversion is to run it backwards. The Swap button turns the YAML into JSON again; if it matches the JSON you started with, nothing was lost. For specs and configs with a schema, validate the data, not just the syntax: paste the spec into the OpenAPI Editor to see its endpoints, or check a config's JSON against its schema in the JSON Schema Validator. And if the YAML will be read by a Python tool, the list under the converter is worth a look: every entry there is a value that would have changed type in PyYAML without its quotes.

Private by design

The JSON you paste here stays on your device: the converter is JavaScript running in this page, and "Open a file" reads files up to 5 MB without uploading them. "Share link" compresses the JSON into the link, after the #, so whoever opens the link sees the same conversion; browsers don't send that part of an address to servers, but treat the link like the file itself. A link holds about 32 KB of compressed text.

FAQ

Does the JSON leave my browser?

No. The JSON is converted by JavaScript in this page, a file you open is read on your device, and a share link holds the JSON after the #, the part of an address browsers never send to a server. The converter records only what kind of conversion ran: the direction, the options and counts such as how many documents were written and how many strings were quoted for YAML 1.1. Never the JSON or the YAML.

Why are some strings in quotes and others not?

A string is written without quotes when every YAML parser reads it back as the same string. Strings that look like another type, such as "true", "42", "1.0" or an empty string, are quoted, and so are strings that YAML 1.1 parsers would misread, such as "no", "on", "2026-03-14" and "22:22". Strings that start with a character YAML reserves, like *, & or @, are quoted too.

Is the key order kept?

Yes, exactly as in the JSON, including keys that look like numbers, which JSON.parse would otherwise move to the front of an object. Number formats are kept too: 1.50 stays 1.50, and integers larger than 253 are copied digit for digit.

Can I get one YAML document per item of an array?

Yes. Turn on "Top-level array as separate documents" and each item of a top-level JSON array becomes its own YAML document, separated by ---. That's the usual layout for several Kubernetes manifests in one file.

Can I convert the YAML back to JSON?

Yes: the Swap button converts the YAML you just made back to JSON, or open the YAML to JSON converter. The round trip gives the same data: strings, numbers, booleans, nulls and key order all come back as they were.

Related tools and guides

  • YAML to JSON Converter: the other direction, with each value that YAML 1.1 and 1.2 read differently listed by line.
  • OpenAPI Editor: write and preview OpenAPI specs in YAML or JSON.
  • OpenAPI Validator: check the converted spec against the official OpenAPI schema.
  • Schema Converter: when the JSON is a schema, turn it into TypeScript, Zod, Pydantic, Go or GraphQL instead.
  • JSON to Schema Generator: infer a JSON Schema from the JSON before you hand the YAML to others.
  • API Tools: all of Schema.biz's tools for JSON, JSON Schema and OpenAPI.