YAML to JSON
YAML to JSON loads YAML with js-yaml and serializes the resulting value with JSON.stringify using two spaces. Comments, anchors, tags, directives, scalar styles, and source locations disappear. Aliases become repeated JSON structures, inferred scalar types carry into JSON, and no application schema is validated.
Runs locally — files stay on your deviceAre YAML comments included in JSON?
No.
JSON cannot preserve YAML source features
Conversion targets the loaded value; comments, anchors, and presentation choices belong to YAML source representation.
How it works
yaml.load parses text and JSON.stringify writes the JavaScript value.
Key concepts
Aliases expand
JSON has no anchor syntax.
Type inference matters
Quoted and unquoted scalars may load differently.
When to use it
- Convert ordinary YAML for a JSON-only consumer.
- Inspect inferred scalar types.
- Create a JSON fixture.
When not to use it
- Do not expect comments or anchors to survive.
- Do not assume application-schema compliance.
- Do not assume every custom YAML tag works.
Worked examples
Mapping
- Input
name: Ana\nactive: true- Expected output
Formatted JSON object
Types serialize.
Comment
- Input
# note\na: 1- Expected output
{"a":1}
Comment disappears.
Anchor
- Input
Shared mapping alias- Expected output
Repeated object data
Identity is not represented.
Common mistakes
Overwriting source
YAML-only context is lost. Correction: Keep the original.
Assuming strings
Parser infers types. Correction: Quote intentionally.
Expecting schema compliance
No contract is loaded. Correction: Validate JSON separately.
Best practices
- Review inferred types.
- Preserve source comments elsewhere.
- Validate the JSON consumer's schema.
Related operations and differences
JSON to YAML
Choose JSON to YAML when you need to convert JSON data into readable YAML.; use YAML to JSON specifically for yaml to json.
CSV to JSON
Choose CSV to JSON when you need to convert a header-based CSV table to JSON.; use YAML to JSON specifically for yaml to json.
JSON to CSV
Choose JSON to CSV when you need to convert an array of JSON objects to CSV.; use YAML to JSON specifically for yaml to json.
JSON to XML
Choose JSON to XML when you need to convert JSON objects into formatted XML.; use YAML to JSON specifically for yaml to json.
XML to JSON
Choose XML to JSON when you need to convert XML elements and attributes into JSON.; use YAML to JSON specifically for yaml to json.
CSV to TSV
Choose CSV to TSV when you need to convert comma-separated data to tab-separated data.; use YAML to JSON specifically for yaml to json.
Limitations and privacy
- No comments, anchors, tags, directives, source positions, application schema, custom mapping, or lossless round trip.
The pasted data is parsed and transformed locally in this browser.
Frequently asked questions
Is output indented?
Yes, with two spaces.
Are comments retained?
No.
Are aliases preserved?
Not as aliases.
Is JSON Schema applied?
No.