Convert a JSON Fixture to a Readable YAML Example

Convert a fictional JSON object to YAML using the JSON to YAML tab, then inspect quoting and round-trip limitations.

By DevSphere Editorial · · 5 min read

Open YAML Tools

Choose a cross-format example

Documentation and configuration examples often use YAML even when the source fixture is maintained as JSON. YAML Tools can convert JSON to YAML through a dedicated tab, making it easier to create a readable draft. The converter uses JSON.parse for its input and a custom serializer for output; it is not a general schema transformer or complete YAML writer. For a safe example, use a fictional workshop schedule with a title, an enabled flag, and a short list of session objects. The workflow below focuses on ordinary nested objects and primitive values. If the real data uses special YAML syntax, multiline blocks, anchors, aliases, or complex scalar values, use a standards-compliant library instead and compare the result in its target consumer. Keep the original JSON as the source of truth because formatting and conversion can change representation.

{
  "workshop": "Sample Lab",
  "open": true,
  "sessions": [
    {"topic": "Sorting", "minutes": 20},
    {"topic": "Filtering", "minutes": 15}
  ]
}

Use the conversion tab

Select the JSON to YAML tab; the input label should read JSON Input. Paste the object and click the action button labelled Convert to YAML. The converter parses JSON, then recursively writes object members and array entries using the selected Indent Size. The output should show workshop and open at the root, followed by sessions with two list entries. The objects in this sample have multiple keys, so each list item is emitted on a dash line with its fields indented below. Click Copy to use the result in an approved document, or Download to save output.yaml. The tool does not preserve the source's line breaks or key spacing. Before sharing the generated example, compare every field and both list elements against the JSON input; successful conversion alone is not a semantic review.

Interpret quoted and unquoted values

The custom serializer writes numbers, booleans, and nulls as bare YAML scalars and quotes some strings that are empty, contain a colon or hash, contain a newline, start or end with whitespace, begin with special indicator characters, or resemble common boolean-like words. Other strings are emitted without quotes. Quoting rules are simplified and may not cover every YAML parser's scalar-resolution behavior. A string such as 001 or a date-like value might be interpreted differently by a full YAML parser than expected from its JSON type. If type fidelity matters, quote sensitive string values explicitly in the generated YAML and test them with the target parser. This UI serializer does not provide a schema or comments to express intended types. For a small documentation example, use simple values that are unambiguous and explain any important type conventions in the surrounding documentation.

workshop: Sample Lab
open: true
sessions:
  -
    topic: Sorting
    minutes: 20
  -
    topic: Filtering
    minutes: 15

Check nested lists and spacing

Use Indent Size to choose two or four spaces for generated child levels. Confirm sessions is an array rather than a single object, and that Sorting remains paired with 20 while Filtering remains paired with 15. When a list item object has only one scalar property, the serializer can render it on the dash line; with two properties it expands the object below the dash. This layout choice affects readability but should not alter the data. Empty arrays are rendered as an inline [] value, and empty objects as {}. Multiline strings use a block indicator in this converter but require special care when moved into another parser. Avoid inserting tabs into indentation. YAML is whitespace-sensitive, and the browser converter's output should still be checked in the actual context where it will be consumed.

Verify round trips with realistic limits

If output is empty, check that JSON Input contains one complete JSON value, with double-quoted keys and no trailing comma. The JSON to YAML action catches parse errors and shows them in the error area. Successful conversion does not mean that the separate YAML Tools parser can faithfully round-trip every possible YAML document; that parser supports only common cases. To test this sample, use the JSON to YAML output as a review artifact and compare its structure manually with the source. If you use the YAML to JSON tab for a basic round-trip experiment, expect only the simple supported subset to be safe and verify the resulting JSON independently. The converter neither validates a deployment schema nor enforces YAML 1.2 semantics. Keep the original JSON, run the target application's full parser, and use synthetic examples where a real configuration could expose sensitive settings.

For documentation, consider adding a short note that the sample was converted from JSON and that JSON does not carry comments. This serializer cannot create comments or retain authorship notes that were outside the input structure. It can also quote or leave plain a string according to simple character tests, so values such as identifiers with leading zeros or dates deserve checking in the intended parser. If readers are likely to copy the output into a real configuration, use values that are unambiguous in both formats and say what the key types mean. Review list item order and object boundaries by comparing each session in the output with its source object. A clean visual result is useful, but a small field-by-field comparison is what catches a swapped duration or omitted entry.

Browse all tutorials