Data Transformation intermediate 12 min

Convert a YAML Config Into JSON for an API

Convert configuration data while preserving booleans, arrays, and nested objects.

Scenario

The deployment config is documented in YAML, but the API endpoint only accepts JSON. Translating by hand looks trivial until types start drifting: YAML's unquoted true must become JSON's boolean true, not the string "true", and the - item list syntax must become a real array. A config that arrives with "active": "true" passes JSON validation and then fails the API's type check — or worse, gets coerced silently.

Broken input

name: demo
features:
  - exports
  - audit
active: true

Goal

Use YAML ↔ JSON Converter to produce JSON that is structurally and type-wise equivalent to the YAML source. The converter parses YAML semantics — indentation, lists, scalars — so types survive the trip.

Tool sequence

  1. Open YAML ↔ JSON Converter.
  2. Paste the YAML with its indentation intact; two-space indents are syntax, and flattening them changes the structure.
  3. Convert to JSON and check the two type-sensitive spots: features must be an array, active must be an unquoted boolean.
  4. Both check out — see the checkpoint below. If active had come out as "true", the YAML side probably had it quoted.
  5. Pretty-print or minify the result for the request body with JSON Formatter, and validate against the API's expected shape with JSON Validator.

Checkpoint output

{
  "name": "demo",
  "features": ["exports", "audit"],
  "active": true
}

features is a real JSON array and active is a boolean — the config means the same thing in both formats.

Common mistakes

  • Quoting values manually during a hand-translation and turning booleans or numbers into strings.
  • Forgetting indentation is meaningful in YAML — a mis-indented key silently becomes a child of the wrong object.
  • Dropping list items when converting a long - item block by hand.
  • Missing YAML's surprise scalars: unquoted no, on, or 1.0 may parse as boolean or number, not the string you intended.

Related tools and lessons