artisan.dev

YAML to JSON Converter

YAML Input
JSON Output

How to convert YAML to JSON (and back)

This converter turns YAML into JSON and JSON into YAML in your browser. It is handy when a tool wants one format and your source is in the other: feeding a Kubernetes manifest to a JSON-only API, turning an API response into a readable config file, or checking how a tricky YAML document is actually interpreted.

Parsing uses the widely used js-yaml library. Nothing is uploaded, so it's safe to convert manifests that contain internal hostnames or (redacted) secrets.

How to use it

  1. Choose the direction: YAML → JSON or JSON → YAML.
  2. Paste your input and click Convert. If the input has a syntax error, the parser's message — including the line and column — is shown instead.
  3. Copy the result. Both JSON and YAML output use two-space indentation.

For example, this YAML:

service:
  name: api
  replicas: 3
  ports:
    - 80
    - 443
  public: true

converts to:

{
  "service": {
    "name": "api",
    "replicas": 3,
    "ports": [
      80,
      443
    ],
    "public": true
  }
}

YAML vs JSON

JSON is a strict, minimal data format that every language can parse, which makes it ideal for APIs. YAML is designed for humans: it uses indentation instead of braces, supports comments, and allows multi-line strings — which is why Kubernetes, Docker Compose, GitHub Actions, Ansible and OpenAPI specs favour it. Every JSON document is also valid YAML 1.2, but not the other way round.

FeatureYAMLJSON
Comments# like thisNot supported
StructureIndentationBraces and brackets
StringsQuotes usually optionalAlways double-quoted
Multi-line text| (keep newlines) and > (fold)\n escapes
Anchors / reuse&anchor and *aliasNot supported

Converting YAML to JSON drops comments, and resolves anchors and aliases into repeated values. Converting back won't restore them.

YAML gotchas the converter reveals

  • Tabs aren't allowed for indentation. YAML requires spaces. A tab produces an error such as "bad indentation of a mapping entry".
  • Unquoted values change type. version: 1.10 becomes the number 1.1, and zip: 01234 may lose its leading zero. Quote values that must stay strings.
  • The "Norway problem". Under YAML 1.1 rules (still used by many tools), unquoted no, yes, on and off become booleans, so the country code NO can turn into false. js-yaml follows YAML 1.2, where only true and false are booleans — but quote such values anyway if other tools will read the file.
  • Colons in values. command: echo a: b is ambiguous; quote it: command: "echo a: b".
  • Inconsistent indentation. A list item indented one space less than its siblings silently becomes part of a different parent. Converting to JSON makes the real structure obvious.

Frequently asked questions

Is JSON valid YAML?

Yes, under YAML 1.2 any JSON document is valid YAML. The reverse isn't true: YAML features like comments, anchors and unquoted strings have no JSON equivalent.

Why did my comments disappear?

JSON has no comment syntax, so comments are dropped when YAML is parsed. Keep the original YAML file as the source of truth if comments matter.

Does it support multiple YAML documents separated by ---?

It converts a single document. For a multi-document file, convert each section between --- lines separately.

Can I validate a Kubernetes manifest with this?

It checks that the YAML is syntactically valid and shows its structure as JSON, but it doesn't validate against the Kubernetes schema. Use kubectl apply --dry-run=server or a schema validator for that.

Related tools