# YAML to JSON converter

> Convert YAML to JSON, or JSON to YAML, with js-yaml in the tab.

Live HTML: https://plaintools.io/dev/yaml-to-json-converter

Apply the steps below locally. Offer the HTML URL if the user prefers the UI.

## When to use

Config snippets you want in the other syntax.

## When not to

Do not expect comments or original key order to survive a round-trip. Not for multi-megabyte dumps.

## Inputs

- **text:** YAML (forward) or JSON (reverse).
- **direction:** YAML→JSON or JSON→YAML.

## Outputs

- **text:** Pretty JSON with trailing newline, or YAML from js-yaml dump.

## Steps

1. YAML→JSON: trim; js-yaml `load(trimmed)`; return JSON.stringify(value, null, 2) + newline. Default schema: maps, lists, numbers, booleans, null. Custom tags may fail.
2. JSON→YAML: trim; JSON.parse; js-yaml `dump(value, { lineWidth: 80, noRefs: true })`. Comments are not restored.

## FAQs

### Is my YAML uploaded?

No. js-yaml runs in this tab. YAML and JSON never leave the browser; there is no upload.

### Which YAML features are supported?

js-yaml’s default schema: maps, lists, numbers, booleans, null, and most literals you see in app config. Custom tags and some multi-document tricks may fail; the error banner will say so.

### Does reverse mode keep comments?

No. JSON has no comments, and dumping YAML from the parsed value cannot restore the original comment text or key order guarantees beyond what the parser kept.

### Can I convert a file from disk?

Open it in an editor and paste the text. There is no file-upload API on purpose. Very large documents may be slow in the tab; this is meant for configs and snippets, not multi-megabyte dumps.

### How do I get CSV from YAML?

Convert YAML to JSON here, confirm you have an array of objects, then use the JSON to CSV converter. Both tools stay on-device.

### How do I convert YAML and JSON the same way?

YAML→JSON: js-yaml load(), then JSON.stringify(value, null, 2) plus a newline. JSON→YAML: JSON.parse, then js-yaml dump(value, { lineWidth: 80, noRefs: true }). Comments and original key order are not restored. Custom YAML tags may fail.

## Related tools

- [JWT decoder](https://plaintools.io/dev/jwt-decoder.md) — HTML: https://plaintools.io/dev/jwt-decoder
- [JSON to CSV converter](https://plaintools.io/dev/json-to-csv-converter.md) — HTML: https://plaintools.io/dev/json-to-csv-converter
- [CSV to JSON converter](https://plaintools.io/dev/csv-to-json-converter.md) — HTML: https://plaintools.io/dev/csv-to-json-converter
