Use Cases
- Generating configuration files from JSON API responses
- Converting JSON to YAML for Kubernetes, Docker Compose, Ansible
- Creating CI/CD config files (GitHub Actions, GitLab CI, CircleCI)
- Improving readability of complex JSON structures
- Converting OpenAPI specs from JSON to YAML format
- Migrating configs from JSON-based systems to YAML-based systems
How It Works
The tool uses thejs-yaml library to serialize JavaScript objects (parsed from JSON) into YAML format:
- Parse JSON (with relaxed syntax support via
parseJsonLoose) - Convert to YAML using
yamlDump()with formatting options:- 2-space indentation
- 120-character line width for readability
- Output YAML string
The tool uses a relaxed JSON parser that accepts unquoted keys, single quotes, and trailing commas, making it forgiving for hand-written JSON.
Input Format
Any valid JSON (or relaxed JSON):Output Format
Examples
Technical Details
Located in
lib/tools/engine.ts:503-504js-yaml (YAML 1.2 serializer):
Formatting Options
- Indentation: 2 spaces (standard for YAML)
- Line width: 120 characters (wraps long strings)
- Flow level: Auto (uses block style for nested structures)
Type Conversion
| JSON | YAML |
|---|---|
true, false | true, false |
123, 123.45 | 123, 123.45 |
null | null or ~ |
"string" | string (unquoted) or 'string' (quoted if needed) |
[1, 2, 3] | - 1\n- 2\n- 3 (block style) |
{"key": "value"} | key: value (block style) |
YAML automatically quotes strings that contain special characters (
:, #, !, etc.) or reserved words (true, false, null, yes, no, on, off).YAML Output Features
Unquoted Strings (Default)
Simple strings are unquoted:Quoted Strings (When Needed)
Strings with special characters are automatically quoted:Block Style Arrays
Arrays use dash notation:Flow Style (Inline)
Short arrays/objects may use flow style:Multi-line Strings
Long strings (>120 chars) are wrapped:Relaxed JSON Parser
The tool accepts non-standard JSON syntax:Common Patterns
API Response to Config File
- Fetch JSON from API:
- Convert to YAML for deployment:
Terraform Variables (JSON → YAML)
OpenAPI Spec Conversion
Convert OpenAPI JSON specs to the more common YAML format for better readability:Limitations
Why are numbers quoted in output?
Why are numbers quoted in output?
YAML quotes numeric-looking strings to preserve their type. For example, version numbers like
"1.2.3" become '1.2.3' to avoid interpretation as a number. This is correct behavior.Can I preserve JSON comments?
Can I preserve JSON comments?
No. JSON does not officially support comments (though JSONC does). When you convert JSON to YAML, any comments in the source are lost. Add comments manually to the YAML output if needed.
Why does 'on' get quoted as 'on'?
Why does 'on' get quoted as 'on'?
on, off, yes, no, true, false are YAML reserved words. When used as keys, they are quoted to prevent misinterpretation as booleans.Related Tools
- YAML to JSON - Reverse conversion (YAML → JSON)
- JSON Format/Validate - Validate and format JSON
- JSON to CSV - Convert JSON arrays to CSV