Home / Converters

JSON to YAML Converter

Runs locally in your browser. Your input is not uploaded.

A JSON to YAML converter rewrites JSON data into indentation-based YAML while preserving the same objects, arrays, values, and types. Choose two- or four-space indentation, optionally sort object keys, and copy or download YAML that round-trips to the original JSON. The conversion cannot create comments or configuration semantics that were absent from the source.

How to Use the JSON to YAML Converter

Preserve key order unless a destination or team convention requires sorting.

  1. Paste valid JSON into JSON input.
  2. Choose 2 spaces or 4 spaces from Indent.
  3. Leave Sort keys off to retain JSON key order, or enable it to sort object keys.
  4. Select Convert to update YAML output. The converter also runs live as you type.
  5. Review the read-only YAML output for indentation, quoted strings, arrays, and nested mappings.
  6. Select Copy to place the YAML on the clipboard or Download .yaml to save it.

JSON and YAML 1.2 Data Models

JSON supports objects, arrays, strings, numbers, booleans, and null. YAML 1.2 can represent all of those types and adds other syntax and features. In fact, a valid JSON document is already valid YAML 1.2, but converting it to block-style YAML can make hand-edited configuration easier to scan.

{
  "service": {
    "name": "api",
    "ports": [8080, 8081],
    "enabled": true
  }
}

becomes:

service:
  name: api
  ports:
    - 8080
    - 8081
  enabled: true

The converter uses js-yaml and emits YAML 1.2 intended to load back to the same JSON data. This is structural equivalence, not byte equivalence: whitespace, braces, commas, and quote style change. JSON object key order is retained unless Sort keys is enabled.

Quoting Strings and the YAML Norway Problem

Plain YAML scalars can resemble booleans, numbers, or null values. The converter quotes strings such as "true", "1.0", "0123", and "null" when needed so a YAML parser does not change their types. It similarly protects words such as "yes", "no", and "on" when ambiguity could undermine round-tripping.

The “Norway problem” describes YAML 1.1 parsers interpreting the country code NO as false because that version recognized several words as booleans. YAML 1.2 narrowed core booleans to true and false, but ecosystems do not all use identical schemas or parser versions. Explicit quoting remains valuable when a string could be misread by a downstream tool.

country: 'NO'
release: '1.0'
postalCode: '0123'
enabled: true

Here, the first three values are strings while enabled is a boolean. Removing quotes can alter application behavior.

Indentation and Editing Rules

YAML uses indentation to define nesting, so whitespace is syntax rather than presentation alone. Choose either 2 spaces or 4 spaces and stay consistent within the document. Tabs are not a safe substitute for indentation spaces.

Sequence markers belong at the correct nesting level, and sibling mapping keys must align. A single misindented line can move a property into another object or produce a parser error. Use an editor with visible whitespace and YAML-aware validation for manual changes.

Long strings are not folded. They remain scalar content without automatic wrapping that could obscure exact values.

Sorting keys can make large objects easier to compare, but order may carry human meaning even though JSON object semantics generally do not depend on it. Configuration files often place identity, version, and required fields first. Leave Sort keys off unless alphabetical consistency is more useful than authored grouping.

Using YAML for Kubernetes and Docker Compose

Kubernetes manifests and Docker Compose files use YAML, but converting arbitrary JSON does not make a valid manifest. Required keys, API versions, object kinds, service definitions, and domain-specific value rules still need to match the target schema.

For Kubernetes, values that look numeric may need to remain strings because environment variables and annotations have specific schemas. Review generated quoting and validate the result against the cluster version or schema used by the project. A syntactically valid YAML file can still be rejected by the API server.

Docker Compose similarly defines expected structures for services, networks, volumes, and other fields. Relative paths, environment interpolation, and scalar coercion can affect behavior beyond basic YAML parsing. Run the platform’s configuration validation command before deployment.

GitHub Actions and OpenAPI Workflows

GitHub Actions workflows are YAML documents with a product-specific schema. Keys such as on deserve attention because YAML 1.1 tooling may historically treat that word as a boolean, even though the intended GitHub Actions key is text. A YAML 1.2-aware conversion and appropriate quoting reduce ambiguity, but workflow validation remains necessary.

OpenAPI documents can be written as JSON or YAML because their data model fits both representations. Converting a valid OpenAPI JSON document can make descriptions and nested paths easier to edit. The conversion does not check references, operation identifiers, schemas, or OpenAPI version compatibility.

Generated YAML is a starting representation. Use the destination’s official validator or linter to check domain rules after conversion.

Comments, Key Order, Round Trips, and Local Processing

JSON has no comments, so the YAML output contains none. A converter cannot infer why a timeout was selected or which team owns a service. Add comments manually after conversion when they provide durable context, then keep the YAML as the source of truth because converting it back through JSON would discard those comments.

YAML supports values that JSON cannot represent directly. If a YAML file later gains timestamps, custom tags, anchors, aliases, or non-string mapping keys, converting through JSON may simplify or reject those constructs. Round-trip guarantees here apply from supported JSON input to generated YAML and back to the same JSON model.

Parsing and generation occur locally with js-yaml. JSON is never uploaded, and the page works offline after it has loaded. Live conversion provides immediate feedback while typing, while Convert reruns the current input and options explicitly.

Check the first parser error before fixing later lines; a missing JSON comma or quote can shift the reported context. The converter expects strict JSON, not a JavaScript object literal with comments, single quotes, or trailing commas.

Frequently Asked Questions

Is every JSON document valid YAML?

Every valid JSON document is valid YAML 1.2. Conversion is still useful because block-style YAML is often easier to edit as configuration.

Why are values such as yes or 0123 quoted?

Quotes preserve them as strings across YAML parsing contexts. Without quotes, some parsers or schemas may interpret boolean-like or numeric-looking text as another type.

Does JSON to YAML preserve comments?

JSON has no comment syntax, so there are no source comments to preserve. Comments added later to YAML will be lost if the document is converted through JSON.

Should I sort YAML keys?

Only when alphabetical consistency helps the workflow. Leaving Sort keys off preserves the JSON order, which may communicate a more useful human grouping.

Is generated YAML automatically valid for Kubernetes?

It is valid YAML when conversion succeeds, but it may not satisfy the Kubernetes schema. Validate API versions, required fields, value types, and resource-specific rules separately.