FreeToolGrid

Developer workflows

JSON to YAML: Examples, Nested Arrays and Type Checks

Open JSON to YAML Converter

JSON and YAML can describe similar structured data, but they are not interchangeable text files. JSON uses explicit punctuation and strict quoting. YAML often expresses structure with indentation and has additional features whose behavior depends on the parser and YAML version. A reliable conversion starts by parsing valid JSON and then serializing the resulting values as YAML.

Use the JSON to YAML Converter when a deployment, automation, or configuration workflow requires YAML. After conversion, validate the result in the application that will consume it. A generic converter cannot know every schema or parser setting used by that application.

JSON to YAML Converter input controls on FreeToolGrid
JSON to YAML Converter

How to convert JSON to YAML

Check the input with the JSON Formatter before converting a large document. JSON comments, single-quoted keys, and trailing commas must be corrected if the source is supposed to be strict JSON. Fix the source deliberately rather than assuming a converter will infer your intent.

Keep an unchanged copy and choose a representative sample with strings, numbers, booleans, lists, and nulls. This makes it easier to see whether the resulting YAML preserves the types you expect. Exact formatting may change without changing the parsed values.

{
  "service": "reports",
  "enabled": true,
  "ports": [8080, 8081],
  "release": "0012"
}
  1. Open the JSON to YAML Converter linked below and paste valid JSON into JSON input.
  2. Select Convert to YAML. Invalid input produces an error instead of partial YAML.
  3. Select and copy the result into the destination file, then validate it with the application that will read it.

Read mappings, sequences, and indentation

A JSON object typically becomes a YAML mapping with key-colon-value entries. A JSON array usually becomes a sequence whose items start with a hyphen. Nested entries are indented beneath their parent. Use spaces for YAML indentation rather than tabs, and keep the nesting consistent.

The following is one possible serialization of the sample. Your converter may choose different legal quoting or layout. Do not judge correctness solely by visual similarity: parse the result using the intended consumer and compare its values.

service: reports
enabled: true
ports:
  - 8080
  - 8081
release: "0012"

Nested JSON example: an array of objects

This application-settings example contains a nested object, an array of worker objects, an empty array, an empty object, and an explicit null. Convert the complete document rather than converting each object separately: the surrounding structure determines where each value belongs.

These are illustrative settings, not a ready-to-deploy configuration for a particular platform. Converting a JSON document does not make its field names valid for Kubernetes, GitHub Actions, or another application's schema.

{
  "service": {
    "name": "reports",
    "workers": [
      { "id": "0012", "enabled": true },
      { "id": "0013", "enabled": false }
    ],
    "labels": [],
    "options": {},
    "fallback": null
  }
}

Equivalent YAML and checks to make

Each hyphen below workers starts one object in the array. The enabled field belongs to that same worker because it aligns with id. Moving it outside that indentation changes the structure, even if the document still parses.

Keep [] and {} when an empty array or empty object is intended. Replacing either with a bare key followed by a colon can turn the value into null. The quoted worker IDs remain strings with leading zeros, while enabled remains a boolean. After conversion, verify both workers, their order, and all three empty or null values.

service:
  name: reports
  workers:
    - id: "0012"
      enabled: true
    - id: "0013"
      enabled: false
  labels: []
  options: {}
  fallback: null

Preserve strings that look like other types

A release identifier such as "0012" is a string, not a number with leading zeros. Quoting it in YAML helps preserve that meaning. The same caution applies to values resembling dates, boolean keywords, or numeric notation. YAML 1.1 and 1.2 parsers can interpret some plain scalars differently.

Do not remove quotes merely because the file looks cleaner without them. Conversely, quoting a true boolean changes it into a string. The safest check is a round trip through the actual target parser and schema. In a JavaScript-based workflow, very large JSON numeric integers may already lose precision during parsing; store exact identifiers as strings.

Troubleshoot invalid JSON and changed values

If conversion reports invalid JSON, check for a comma after the last item, a missing closing brace or bracket, comments, and keys without double quotes. A Windows-style path inside a JSON string needs escaped backslashes. Fix the source rather than globally replacing punctuation, which can corrupt valid text inside strings.

Duplicate object keys are another hazard: JavaScript's JSON parser keeps the last value for a repeated key. Conversion cannot recover the overwritten value, so remove accidental duplicates before converting. Exact integer identifiers above JavaScript's safe integer range should be quoted in the original JSON; adding quotes only after conversion cannot restore lost precision.

If YAML parses but the target application rejects it, check the application's required keys and value types. A syntactically valid mapping is not proof of a valid deployment configuration. Parser-version differences, especially YAML 1.1 versus 1.2 scalar rules, also need validation with the actual consumer.

Check the consumer before deploying

Conversion preserves a data structure, not every formatting feature or application convention. JSON has no comments to carry over, and YAML-specific anchors, aliases, or custom tags are not created just because the destination supports them. Key order is not a substitute for application semantics.

Run the destination's configuration validation or dry run when available. Check required fields, environment names, paths, and secrets separately. Browser-local conversion avoids sending the document to a FreeToolGrid application server, but private configuration should still be handled carefully on shared devices.

  1. Validate the original JSON.
  2. Convert a copy, not the only original.
  3. Check strings, booleans, numbers, arrays, and null values.
  4. Validate the YAML with the consuming application before deployment.

Values to inspect after conversion

Values to inspect after conversion
JSON valueIntended typeWhat to verify
"0012"StringLeading zeros survive
trueBooleanNot converted to quoted text
[8080, 8081]Array of numbersTwo numeric list items
nullNullNot the string "null"

Common questions

Can I rename a .json file to .yaml instead?

Some YAML 1.2 parsers accept JSON syntax, but parser behavior and application expectations vary. Use the required format and validate with the actual consumer rather than relying on the extension.

Will conversion add comments explaining my configuration?

No. A converter does not know the business meaning of each field. Add accurate comments separately when the target format and application permit them.

Can I convert a JSON array at the top level?

Yes. A valid top-level JSON array converts to a YAML sequence. Check that the destination accepts a sequence; some configuration schemas require an object instead.

Why are some numbers wrapped in quotes?

A quoted value in the source JSON is a string, even when it contains only digits. Quotes in YAML can preserve leading zeros or prevent a string from being interpreted as another type. Do not remove them without checking the parsed value.

Further reading

Business

Money

Everyday math

Images & files

Writing

Browse all guides