Document Workflow

Convert JSON and YAML configuration files safely

Convert JSON and YAML configuration files while checking duplicate keys, number precision, comments, anchors, aliases, multi-document streams, and destination schemas.

Written and tested by Published: Reviewed:

How this workflow was checked

The review loaded the unmodified “A small service config converted from JSON to YAML” sample into JSON to YAML and YAML to JSON Converter. We exercised the path from “Identify the source standard and destination consumer” to “Compare the structure and edge values”, checked the displayed or downloaded result against the example, and separately examined “Assuming valid YAML means valid Kubernetes or CI configuration” and “Allowing duplicate keys to choose a winner”.

The service object, two numeric ports, date-like string, and boolean retained their intended structure in YAML and survived conversion back to equivalent JSON.

Problem

JSON and YAML can represent the same basic mappings, sequences, strings, numbers, booleans, and empty values, but the formats are not interchangeable in every detail. YAML comments, anchors, aliases, tags, and document streams do not have equivalent JSON syntax. Duplicate keys and long numeric literals can also disappear or change when a weak converter keeps only the last key or rounds a browser number. This workflow checks the source, identifies syntax that cannot survive, and validates the result in the destination product before it is deployed.

Sources and standards

These authoritative references define the formats or security boundaries used in this workflow. Tool-specific verification is documented separately above.

When to use this

  • An application settings file must move from JSON to a YAML-based config system.
  • A single Kubernetes, Docker Compose, or CI YAML example needs a JSON representation for inspection or tooling.
  • A support case needs a small reproducible config in the format preferred by another team.
  • A repository change should be reviewed in both JSON and YAML before it is committed or deployed.

Steps

  1. Step 1

    Identify the source standard and destination consumer

    Confirm that the YAML is intended for YAML 1.2 behavior and that the source contains one document. Record the product that will consume the result, such as kubectl, Docker Compose, a CI provider, an API client, or an application settings loader. Format conversion cannot replace that product's schema validation.

  2. Step 2

    Reduce the file to the configuration that must move

    Remove unrelated secrets, generated sections, disabled examples, and environment-specific values before pasting. Keep a backup of the original file because comments, scalar styles, anchors, and aliases may not have an equivalent representation in the destination format.

  3. Step 3

    Convert one document with strict loss checks

    Choose JSON to YAML or YAML to JSON, select two-space or four-space indentation, and use Pretty JSON while reviewing. Fix strict syntax locations, duplicate keys, non-string YAML collection keys, unsupported tags, and numeric literals that would change instead of allowing the converter to guess.

  4. Step 4

    Review comments, anchors, aliases, and scalar types

    YAML comments are removed because JSON has no comment syntax. Bounded anchors and aliases are expanded into repeated values, so the relationship itself is lost. Verify quoted date-like strings, leading-zero identifiers, null values, booleans, multiline strings, and every value called out by a warning.

  5. Step 5

    Compare the structure and edge values

    Compare top-level keys, nested paths, array lengths, key order where your review process relies on it, and the reported node and maximum-depth counts. Pay special attention to __proto__, constructor, integer-looking key names, large identifiers, negative zero, and decimal values with many significant digits.

  6. Step 6

    Validate and test in the destination

    Download the current result and run the destination validator or a dry run. For Kubernetes use its schema-aware tooling, for Docker Compose use its config validation, and for CI or application settings use the provider's own parser. Compare the effective configuration with the original intent before committing or deploying.

Example

A small service config converted from JSON to YAML

Input

{
  "service": {
    "name": "api",
    "ports": [8080, 8081],
    "release": "2026-07-15",
    "enabled": true
  }
}

Output

service:
  name: api
  ports:
    - 8080
    - 8081
  release: 2026-07-15
  enabled: true

Common mistakes

Assuming valid YAML means valid Kubernetes or CI configuration

YAML syntax only describes the data format. Product schemas still decide which keys, value types, versions, and combinations are allowed.

Ignoring comments and anchor warnings

Comments may contain operational context, and anchors may encode intentional reuse. Move important comments into documentation and inspect every expanded value before discarding the original file.

Allowing duplicate keys to choose a winner

Different parsers may keep the first value, keep the last value, or reject the document. Rename or remove duplicate keys explicitly before conversion.

Treating identifiers as ordinary numbers

Account IDs, image tags, postal codes, and long build numbers may need exact text or leading zeros. Quote them in the source when they are identifiers rather than quantities.

Converting a multi-document YAML stream as one object

A stream separated by --- contains several root documents, while JSON conversion produces one root value. Split the stream and convert each document deliberately.

FAQ

Is every JSON document valid YAML?

JSON syntax is compatible with the YAML 1.2 model, but this converter parses JSON strictly and serializes a clean YAML representation rather than preserving JSON punctuation.

Why are YAML comments missing from JSON?

JSON has no standard comment syntax. Store important rationale in documentation or another explicit field before converting.

What happens to YAML anchors and aliases?

Within the safety limit, aliases are expanded into repeated JSON values and a warning is shown. Circular aliases and excessive expansion are rejected.

Why does the converter reject some large numbers?

Browser numbers cannot preserve every long integer or high-precision decimal. Rejection prevents the output from containing different digits; quote identifiers or exact decimals when text preservation is required.

Can I convert several YAML documents at once?

No. Split a stream at its document separators and convert each root document separately so the intended JSON shape is explicit.

How do I verify the converted configuration?

Review warnings and structural counts, compare sensitive edge values, then run the destination application's schema validator or dry-run command before replacing the original.