YAML to JSON converter

Paste a YAML file such as docker-compose.yml or a settings file to get formatted JSON. If something is wrong you see the line number and the reason.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter yaml text and indentation.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

YAML is read with the YAML 1.2 core schema: null and ~ become null, true and false become booleans, decimal, 0x hex and 0o octal numbers become numbers, and everything else is text. A | block keeps line breaks and a > block folds lines with spaces. The JSON is then written with 2 or 4 space indentation.

Example

Inputs: Indentation = 2 spaces. Result: JSON: { "app": "toolsahla", "port": 8080, "debug": false, "languages": [ "ar", "en" ], "database": { "host": "localhost", "user": "admin" }, "welcome": "Welcome to ToolSahla\nأهلا بك\n" }.

# App settings
app: toolsahla
port: 8080
debug: false
languages:
  - ar
  - en
database:
  host: localhost
  user: admin
welcome: |
  Welcome to ToolSahla
  أهلا بك
{
  "app": "toolsahla",
  "port": 8080,
  "debug": false,
  "languages": [
    "ar",
    "en"
  ],
  "database": {
    "host": "localhost",
    "user": "admin"
  },
  "welcome": "Welcome to ToolSahla\nأهلا بك\n"
}

Limits and caveats

  • The tool supports a clear YAML subset: maps, lists, scalars, quoted strings, | and > block scalars and [ ] and { } flow collections. Anchors &, aliases *, tags ! and multiple documents are rejected with a clear message.
  • Comments are dropped because JSON has none.
  • .inf and .nan have no JSON equivalent and give an error.

Questions about this tool

Why do I see "anchors are not supported"?

The file uses & and * to repeat a part. Write the repeated values out in full and convert again.

Do yes and no become true and false?

No. Under YAML 1.2 yes and no stay text; only true and false are booleans.

What does the tab indentation error mean?

YAML does not allow the Tab key for indentation. Replace it with spaces on the line shown.