YAML to JSON converter
Convert YAML to JSON and back in your browser, with warnings for the Norway problem, version numbers read as floats, alias bombs and duplicate keys.
Read as YAML 1.2, the current version. The checks below say where a YAML 1.1 reader would see something else.
The result appears here.Everything you type here stays in your browser. Nothing is sent to HardenKit or to anyone else.
How to use the YAML to JSON converter
- Choose YAML to JSON, or JSON to YAML.
- Paste the input, or load the example.
- Copy the converted output.
- For YAML, read the findings and quote the values they point at.
About this tool
YAML and JSON describe the same kind of data: mappings, lists, strings, numbers, booleans and null. YAML is written for people, with indentation and few quotes, and is what Kubernetes, Docker Compose, GitHub Actions and most CI systems read. JSON is strict and is what programs exchange. Converting YAML to JSON shows exactly what a parser understood, which is often not what the author meant.
The gap comes from unquoted values. Under YAML 1.1, which PyYAML and many other libraries still implement, yes, no, on and off are booleans, so a list of country codes with NO in it gains a false. An unquoted 3.10 is a float and becomes 3.1, which is how a build ends up on the wrong Python. YAML 1.2 fixed the booleans, so two tools can read one file differently. The converter reads YAML 1.2 and flags each such value.
It also flags two structural risks. Duplicate keys in a mapping are forbidden by the specification but accepted by many parsers, which silently keep one. Anchors and aliases let a small file expand into gigabytes, the billion laughs attack, so expansion here is capped and a document that exceeds the cap is refused. These checks are a set of rules and do not replace a review of the file.
Sources
Questions
In YAML 1.1 the unquoted words yes, no, on and off are booleans. The country code for Norway, NO, therefore loads as false. YAML 1.2 removed this, but many parsers still follow 1.1, so quote such values.
An unquoted 3.10 or 1.20 is parsed as a floating point number, and the trailing zero has no meaning for a number, so it becomes 3.1 or 1.2. Put version numbers in quotes.
YAML 1.2 was designed so that valid JSON is valid YAML, and in practice almost all JSON loads in a YAML parser. The reverse is not true: YAML has comments, anchors, multiple documents and types that JSON lacks.
A small document whose aliases refer to anchors that contain more aliases, several levels deep. Expanding it multiplies the data at each level until memory runs out. Parsers that load untrusted YAML need a limit on alias expansion.
They are lost. JSON has no comments, and every alias is replaced by a copy of the data it points to. Converting back gives YAML with the same data but without the original layout.