YAML to JSON and JSON to YAML Converter – Free

Paste a YAML document to get indented JSON, or paste JSON to get block-style YAML. This YAML to JSON converter parses everything in your browser and reports the first syntax error it finds.

How to use the YAML ↔ JSON tool

  1. Set Source format to YAML to produce JSON, or to JSON to produce YAML.
  2. Paste one document into the YAML or JSON box.
  3. Select Convert. The Example button loads a small YAML mapping that contains a list.
  4. Check the Result box, then select Copy or use the Download link, which saves data.json or data.yaml.

How YAML maps to JSON

Both formats describe the same shapes: mappings (objects), sequences (arrays) and scalars. YAML 1.2 was designed so that valid JSON is also valid YAML, which is why conversion in either direction is mostly mechanical.

The tool parses with the yaml library for JavaScript and its default YAML 1.2 core schema. Under that schema only true and false are booleans. The words yes, no, on and off stay strings, and so does the country code NO, which YAML 1.1 parsers turn into false. Numbers written as 0o17 or 0x1F become 15 and 31, and ~ or an empty value becomes null.

Worked example: a service config as YAML and JSON

The YAML below uses block style for the mapping and flow style for the hosts list. The JSON result spells out the same structure with two-space indentation: 8080 and 2.5 stay numbers, false stays a boolean and null stays null. Converting that JSON back gives block-style YAML with the hosts written as a dashed list.

service:
  name: api
  port: 8080
  debug: false
  hosts: [a.example.com, b.example.com]
  timeout: 2.5
  note: null

{
  "service": {
    "name": "api",
    "port": 8080,
    "debug": false,
    "hosts": [
      "a.example.com",
      "b.example.com"
    ],
    "timeout": 2.5,
    "note": null
  }
}

What changes or gets lost in conversion

In the JSON to YAML direction, strings that would read as another type are quoted, so "123" and "true" keep their quotes, and long strings are folded at about 80 columns. The string yes is written without quotes, which is correct for YAML 1.2 but read as a boolean by YAML 1.1 parsers such as PyYAML. Quote it by hand if your consumer is one of those.

Going from YAML to JSON keeps the data but not the styling, and a few YAML features have no JSON equivalent:

  • Comments are discarded, because JSON cannot hold them.
  • Anchors and aliases are expanded into repeated copies. Reusing one anchor 50 times or more, or fewer when aliases are nested, is refused with Excessive alias count indicates a resource exhaustion attack.
  • The merge key << is not applied. It appears in the JSON as an ordinary key named <<.
  • The values .inf and .nan become null, since JSON has no way to write them.
  • Long integer IDs, high-precision decimals and numeric exponents keep their values in both directions. If two YAML keys map to the same JSON property name, rename one before exporting.

Syntax errors you are likely to see

YAML mode stops at the first error and shows the parser's message with a line and column. JSON mode uses the browser's strict JSON parser.

  • Tabs are not allowed as indentation: YAML indentation must be spaces.
  • Map keys must be unique: one key appears twice within a mapping.
  • Source contains multiple documents: the input has a --- separator between documents. Convert each document separately.
  • Nested mappings are not allowed in compact mappings: usually a line indented too far under a key that already has a value.
  • In JSON mode, single quotes, unquoted keys, comments and trailing commas are all rejected.

Frequently asked questions

Can I convert a YAML file with several documents?

Not in one pass. The tool reads a single document, and a --- separator followed by a second document raises an error. Split the stream at the separators and convert each part on its own.

Why did yes or NO stay a string instead of becoming a boolean?

The parser follows YAML 1.2, where only true and false are booleans. YAML 1.1 tools treat yes, no, on and off as booleans too, which is the cause of the well-known Norway problem. If you want a boolean, write true or false.

Are YAML comments kept in the JSON?

No. JSON has no comment syntax, so every comment is dropped. Keep the original YAML file if the comments matter.

Is my configuration sent to a server?

No. The YAML library is loaded into the page and parsing happens in your browser. That matters for config files, which often hold hostnames, tokens and passwords; they stay on your device.

Related tools