A deployment tool wants JSON. Your project keeps its settings in YAML. Somewhere between the two, somebody opens a text editor and starts converting by hand, swapping indentation for braces and hoping nothing breaks. It works until the file grows, a date changes shape, or two keys quietly collide.

The YAML to JSON Converter on Ovatly does the mechanical part in your browser. It uses js-yaml, the standard JavaScript YAML parser, and it works in both directions. This guide covers the plain conversion first, then the three surprises worth knowing about before they reach production: timestamps, anchors and duplicate keys.

Contents

  • Quick answer
  • Why YAML has to become JSON at all
  • How to convert YAML to JSON, step by step
  • Worked example: a two-line config
  • Surprise one: timestamps become ISO strings
  • Surprise two: anchors are expanded
  • Surprise three: duplicate keys are an error
  • The reverse direction: JSON to YAML
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

Open the YAML to JSON Converter, choose the YAML to JSON direction, paste your YAML, press Convert, and copy the result or download it with the matching file extension. Watch for three documented behaviours: YAML timestamps come out as ISO date-time strings, anchors are expanded into plain values, and duplicate keys stop the conversion with an error instead of being silently overwritten. Nothing is uploaded; parsing runs in your browser.

Why YAML has to become JSON at all

YAML is written for humans: indentation instead of brackets, comments allowed, values that can stay unquoted. JSON is written for machines: strict punctuation, quoted keys, and a short list of types. That strictness is why so many APIs, config loaders and command line tools accept JSON and only JSON.

Converting is therefore a normal step when a YAML config has to feed a JSON-only tool, be embedded inside a JSON payload, or be checked by a JSON validator. The risk is not the braces. The risk is the places where YAML is more expressive than JSON, because those are the places where a value can change shape on the way across. The three sections after the worked example cover exactly those places.

How to convert YAML to JSON, step by step

  1. Choose the direction. The selector at the top of the YAML to JSON Converter switches between YAML to JSON and JSON to YAML; this guide uses YAML to JSON.
  2. Paste your YAML document into the input box.
  3. Press Convert.
  4. Read the result before you take it. Check any dates, and look for values you defined once with an anchor and reused, because they will now appear written out in full.
  5. Copy the JSON, or download it with the matching file extension, and feed it to the tool that needed JSON.

Worked example: a two-line config

The smallest useful config makes the shape change obvious. This YAML:

name: Ana
age: 31

converts to:

{
  "name": "Ana",
  "age": 31
}

Two things happened, and both are typical. The keys gained quotes, because JSON requires quoted keys. And the values kept their types: Ana stays a string and 31 stays a number, because YAML and JSON agree on those types. When a conversion looks wrong, it is rarely at this level. It is in the three cases below.

Surprise one: timestamps become ISO strings

YAML recognises an unquoted date as a timestamp, not as text. JSON has no date type at all, so the converter writes the value as an ISO date-time string, the only date representation JSON has. The information survives, but the type changes: a consumer that expected a date now holds a string and must parse it back.

If a date in your YAML was only ever meant as a label, quote it in the YAML so it is a string from the start. Quoting takes away the surprise entirely, because a quoted value crosses as the exact text you wrote.

Surprise two: anchors are expanded

YAML lets you define a value once with an anchor and point to it from several places with an alias. JSON has no references, so there is nowhere for an alias to point. The converter expands anchors into plain values: each alias is replaced by the full value it referred to.

The output is correct and self-contained, but it can be much larger than the source, and editing the JSON later means editing every expanded copy. Keep the YAML as the file you maintain, and treat the JSON as a build product you regenerate.

Surprise three: duplicate keys are an error

A YAML mapping that uses the same key twice is ambiguous: two values compete for one name. Strict parsing treats that as an error, and the converter reports it rather than silently overwriting the first value with the second.

That refusal is a favour. A converter that guessed would let you ship whichever value happened to come last, and the bug would surface somewhere far from the config file. When the error appears, find the repeated key in your YAML, decide which value is real, delete the other, and convert again.

The reverse direction: JSON to YAML

The same tool converts JSON back to YAML with the same selector, which is handy when a JSON response or export needs to become a readable config file. The download filename changes to match the direction you chose.

The surprises mostly run one way, because JSON is the smaller language: anything JSON can express, YAML can hold. It is the trip from YAML to JSON, covered above, where expressive features have to be flattened into strings, plain values or outright errors.

Limitations and honest tradeoffs

The converter covers the YAML 1.2 core features used by typical config files, through js-yaml with its default schema. YAML features with no JSON equivalent are resolved or rejected by the parser: anchors are expanded, and custom tags are either resolved or reported rather than carried across into the output.

Keys that are not strings in YAML are converted following the parser's rules, because JSON keys must be strings. If your YAML leans on numeric or boolean keys, check those entries in the output by hand before you rely on them.

And the converter converts; it does not validate your configuration against the rules of whatever tool will consume it. A file can be perfectly good JSON and still be the wrong shape for its destination, so a quick read of the result is part of the job.

Common mistakes

  • Converting by hand. Manual conversion is where commas and quotes go missing. Paste, convert, and spend your attention on the values instead.
  • Leaving dates unquoted when they are labels. An unquoted date becomes a timestamp and then an ISO string. Quote dates that are meant to stay text.
  • Editing the JSON and forgetting the YAML. Anchors expand and values multiply in the output. Keep one source file and regenerate the other.
  • Fighting the duplicate key error. The error is the tool refusing to guess which value you meant. Fix the mapping rather than looking for a way to force the conversion.

FAQs

Does the tool only convert YAML to JSON? No. It works in both directions. A direction selector switches between YAML to JSON and JSON to YAML, and the download filename changes to match.

Why did my date turn into a long string? YAML treats an unquoted date as a timestamp. JSON has no date type, so the value is written as an ISO date-time string, which is the only date representation JSON has.

What happens to YAML anchors? Anchors are expanded into plain values in the JSON output, and each alias is replaced by the full value it pointed to, because JSON has no way to reference a value defined elsewhere.

Why did my conversion stop with an error about a key? Duplicate keys in a YAML mapping are an error in strict parsing. The converter reports them instead of silently overwriting the first value, so you can fix the mapping and convert again.

Is my config file uploaded? No. Parsing runs in your browser with js-yaml, which matters for config files that may contain internal names, hosts or settings.

Conclusion

YAML to JSON is a short job once the surprises are known: pick the direction, paste, convert, and check the dates, anchors and repeated keys before the output goes anywhere. The YAML to JSON Converter keeps the whole job in your browser, which matters for config files full of internal names. If your wider workflow includes preparing the pages those configs serve, our guide to counting words on a sales page before a review pairs well with this one. For more guides in this series, see our Data and JSON Tools guides, which pair each technique with the free tool that performs it.

References