calculate.sh DE

This tool runs in your browser using JavaScript. If it does not appear, please enable JavaScript or reload the page. The description below explains how it works.

YAML Formatter

Format YAML and convert it to JSON - in your browser. Paste YAML into the input box and the tool normalizes the indentation live while keeping every comment exactly where it belongs, warns you about duplicate keys, and renders the same document as pretty JSON below. Everything runs locally on your device: nothing is printed to the console, nothing is uploaded, so you can safely work with configuration files that contain secrets.

What is YAML?

YAML (short for "YAML Ain't Markup Language") is a human-friendly format for describing structured data. It is used for configuration files everywhere: Docker Compose files, Kubernetes manifests, GitHub Actions workflows, pre-commit hooks, Ansible roles, and many service tools such as this project's own Maven and CI configuration. Instead of the heavy punctuation of JSON, YAML uses indentation to show nesting:

server:
  host: api.example.com
  port: 443
  tls: true
endpoints:
  - /health
  - /metrics

A plain-text editor shows you the structure; the indentation does the work that braces and quotes do in JSON.

How to use

Paste YAML into the Input pane. The tool parses it on every keystroke and updates the two result panes below:

  • Formatted YAML - the same document, re-indented consistently to your chosen width. Use the Indent selector in the toolbar to switch between 2 spaces and 4 spaces. A tab option is deliberately not offered: the YAML specification forbids tabs for block indentation, and block-style mappings and sequences must use spaces.
  • JSON Conversion - the semantically identical content as pretty-printed JSON, with its own Copy button.

Both panes have a Copy button that puts the result on your clipboard; a fallback path covers browsers where the Clipboard API is unavailable.

Comments are preserved

The formatting pass keeps the document's comments: header comments above the document, comments between keys, and the # inline comments trailing a value on the same line all survive. In the YAML library that powers this tool, comments live in the syntax tree rather than being stripped on parse, which is why they reappear in the output in the correct position. This is the main reason the tool formats instead of minifying - a "minify" mode for YAML is meaningless, because throwing away the comments would destroy the only reason many files are written in YAML in the first place.

Duplicate keys

Because repeated keys are a real hazard in merged configuration, the tool checks every mapping and shows an amber Duplicate key warning below the formatted output. The message gives the key, the location of the second occurrence, and the location of the first. Strictly speaking, the YAML specification requires every key in a mapping to be unique, so a document with duplicate keys is not valid YAML. Many parsers are lenient anyway, and so is this tool: by its own design decision it keeps parsing, the last value wins in the JSON conversion, and the warning makes the problem visible so you can fix the source file. Pairs in different sibling mappings are never compared against each other, so a name key under server and another under client does not trigger a false positive.

Errors with line and column

An unfinished block or a broken flow sequence raises an error that reports the exact line and column, for example Flow sequence in block collection must be sufficiently indented and end with a ] (line 2, column 1). The message is shown in the formatted-output pane and the JSON pane waits politely until the input parses again.

Converting YAML to JSON

The JSON Conversion pane rerenders the parsed document as JSON:

  • Anchors and aliases are expanded - a: &v 1 followed by b: *v produces "a": 1, "b": 1 in the JSON.
  • Block scalars (| and > styles) become multi-line JSON strings with real newlines.
  • Timestamps such as 2026-10-05 or 2026-10-05T12:00:00Z stay strings, exactly as written - the YAML 1.2 core schema has no date type.
  • Booleans and numbers map to their JSON equivalents; null stays null. Integers keep every digit, even beyond JavaScript's safe range: id: 9007199254740993 stays 9007199254740993 in both panes.
  • An input that contains only comments and no document content converts to the JSON value null.

What to know

  • One document only - YAML streams that contain several documents separated by --- are rejected with a clear message. Format one document at a time.
  • Merge keys stay literal - the <<: merge syntax is honored as regular YAML syntax but is not resolved into the object it merges; the JSON conversion keeps the << key as it appears.
  • Beyond JSON's limits - .inf and .nan have no JSON representation and produce a clear error instead of a silent null. Decimal numbers with more digits than a 64-bit float can hold (for example 1.00000000000000001) are flagged with an amber Precision warning that shows the value the conversion will actually use.
  • Windows line endings - CRLF input is handled; the tool's own output uses standard LF endings.
  • Pair with the JSON formatter - to clean up the output afterwards, or to go the other direction, the JSON Formatter validates, pretty-prints, and minifies the JSON you convert.