Skip to main content

Data & Format / JSON Tools

JSON to YAML

JSON to YAML converts between JSON and YAML in both directions, entirely in your browser, and tells you up front which YAML features, comments, anchors and multiple documents, cannot survive a trip through JSON.

Sponsored

This space is reserved for a sponsor.

Sponsored

This space is reserved for a sponsor.

How to use

  1. 1

    Paste JSON or YAML

    Either format goes into the input box; the tool detects the direction from what you paste, so you do not need to tell it which way to convert.

  2. 2

    Convert

    One click produces the other format on the right. The conversion runs locally, so neither document is uploaded anywhere.

  3. 3

    Note what was dropped

    If your YAML used comments, anchors or multiple documents, the output flags that those features could not be carried over, so you know the result is not a perfect clone.

  4. 4

    Validate as you go

    Invalid input is reported with the line where parsing stopped, so you can fix the syntax before converting rather than guessing why the output is empty.

  5. 5

    Copy the result

    Copy the converted text to your clipboard. The text never leaves your browser and nothing you paste is sent to any server.

Key facts

  • SupersetYAML 1.2 is a superset of JSON: every valid JSON document is also valid YAML, so JSON parses cleanly as YAML.Source:YAML 1.2 spec
  • Key orderYAML preserves the order of mapping keys as written, whereas a JSON object key order is not semantically significant.Source:RFC 8259 §1
  • AnchorsYAML anchors and aliases have no JSON equivalent and are inlined to their values during conversion.Source:YAML 1.2
  • CommentsComments are not part of the YAML data model and are dropped when converting to JSON.Source:YAML 1.2
  • PrivacyConversion runs entirely client side; no document is transmitted to any server.Source:This tool

Frequently asked questions

Does this tool upload my YAML or JSON?

No. The conversion runs entirely in your browser and no network request leaves your machine. Configuration files and API payloads frequently contain secrets, tokens or infrastructure details, and any service that round-trips your text through a server has written it into that server logs. Open the developer tools, watch the network panel, paste a document and convert it; no request appears. The only browser interface the page uses is the clipboard, and only when you press Copy.

What does a YAML to JSON to YAML round trip lose?

It loses comments, because comments are not part of the YAML data model and are discarded when the document is parsed. It loses anchors and aliases, because JSON has no equivalent concept and the referenced value is inlined where it was used rather than referenced. It keeps only the first document when the input contained several separated by three dashes. It may also reorder keys, because although YAML preserves the order you wrote, the JSON object it passes through does not guarantee to preserve that order on the way out. And some YAML values that carry rich typing, such as timestamps, may be reinterpreted as plain strings.

Are YAML anchors and aliases preserved?

No. JSON has no notion of a reference to another part of the document, so when YAML is parsed the anchor is resolved and its value is written out in full at every place the alias appeared. On the way back to YAML there is no information left to reconstruct the original anchor, so the output is correct but verbose: the same structure appears repeatedly instead of being referenced once. If you rely on anchors to keep a large document DRY, treat the JSON form as a lossy intermediate rather than a faithful copy.

Does it handle multi-document YAML?

It converts the first document and ignores any further documents separated by the three-dash marker, with a warning that the others were not included. This is unavoidable given that JSON describes exactly one document; there is no JSON representation of a stream of documents. If you need every document, split the stream at the dash markers and convert each one separately, then recombine them yourself.

Why did my number turn into a string, or my date change?

YAML has a richer type system than JSON: it infers integers, floats, booleans, null and even timestamps from context, while JSON has a single number type plus strings, booleans, null and arrays or objects. When YAML becomes JSON a timestamp usually becomes a string, a value like on may become the boolean true, and a quoted number stays a string. When JSON becomes YAML the reverse happens: a JSON string that looks like a date is not automatically a YAML timestamp unless it matches the strict format. If types matter, quote values explicitly in YAML and check the output.

Related tools

Sponsored

This space is reserved for a sponsor.