JSON to YAML
JSON to YAML parses standard JSON, then js-yaml emits YAML with two-space indentation, 100-column wrapping, and references disabled. Data meaning is generally carried across, but exact JSON number precision, object key order expectations, escape spelling, and lexical formatting are not preserved. The output has no comments or schema annotations and may use YAML scalar styles that require review in the target application.
Runs locally — files stay on your deviceAre JSON comments converted?
No. Standard JSON comments are invalid.
Conversion maps data models, not source text
JSON values fit largely within YAML's data model, but serialized syntax and consumer schemas remain different.
How it works
JSON.parse builds a value and yaml.dump writes it with fixed options.
Key concepts
JSON validates first
Trailing commas and comments fail.
YAML style is regenerated
Quoting and wrapping are chosen by js-yaml.
When to use it
- Create a YAML version of a small JSON configuration.
- Move flat fixture data into YAML.
- Inspect nested data in another syntax.
When not to use it
- Do not expect comments or original formatting.
- Do not assume destination-schema compatibility.
- Do not rely on unsafe integer preservation.
Worked examples
Object
- Input
{"name":"Ana","active":true}- Expected output
name: Ana\nactive: true
Primitive types map.
Array
- Input
[1,2]- Expected output
YAML sequence
Order remains.
Large integer
- Input
Beyond Number safe range- Expected output
Potential rounding
JSON.parse uses JavaScript numbers.
Common mistakes
Expecting schema conversion
Only syntax/data representation changes. Correction: Validate the target schema.
Using comments
JSON rejects them. Correction: Migrate notes separately.
Assuming byte equivalence
Serialization differs. Correction: Compare parsed values.
Best practices
- Review YAML scalar types.
- Keep source under version control.
- Test the actual YAML consumer.
Related operations and differences
YAML to JSON
Choose YAML to JSON when you need to convert YAML data into formatted JSON.; use JSON to YAML specifically for json to yaml.
CSV to JSON
Choose CSV to JSON when you need to convert a header-based CSV table to JSON.; use JSON to YAML specifically for json to yaml.
JSON to CSV
Choose JSON to CSV when you need to convert an array of JSON objects to CSV.; use JSON to YAML specifically for json to yaml.
JSON to XML
Choose JSON to XML when you need to convert JSON objects into formatted XML.; use JSON to YAML specifically for json to yaml.
XML to JSON
Choose XML to JSON when you need to convert XML elements and attributes into JSON.; use JSON to YAML specifically for json to yaml.
CSV to TSV
Choose CSV to TSV when you need to convert comma-separated data to tab-separated data.; use JSON to YAML specifically for json to yaml.
Limitations and privacy
- No comments, schema conversion, custom tags, multi-document output, source maps, lossless numbers, or style controls.
The pasted data is parsed and transformed locally in this browser.
Frequently asked questions
Are arrays supported?
Yes.
Are comments preserved?
No.
Is a YAML schema validated?
No.
Can number precision change?
For unsafe integers, yes.