// formatters
YAML Quote Style Converter.
Convert YAML string scalars between unquoted, single-quoted, and double-quoted styles safely.
YAML input
Converted
YAML quote styles explained.
YAML supports three string styles: plain (no quotes), single-quoted, and double-quoted. Each has different behavior for special characters, escape sequences, and multi-line strings. This tool converts all string values to one consistent style.
Plain strings are the most readable but have restrictions: they can't contain certain special characters (: [ ] , & * # | > ' " % @ `) at the start, and they're interpreted as numbers, booleans, or null if they match those patterns. Single-quoted strings treat everything literally — no escape sequences, no type interpretation. '42' is the string "42", not the number 42.
Double-quoted strings support escape sequences: \n (newline), \t (tab), \\ (backslash), \" (quote). Use double quotes when you need literal control characters in the string. Double-quoted strings also allow multi-line values with explicit line breaks.
When to use each style.
Plain — use for simple strings without special characters. Most readable. Single-quoted — use when the string contains colons, brackets, or other YAML special characters but doesn't need escape sequences. Double-quoted — use when the string contains escape sequences, special characters at the start, or needs to preserve exact whitespace.
Teams often standardize on one style for consistency. If your project uses single quotes everywhere, paste your YAML through this tool to convert all strings to single-quote style. The tool preserves non-string values (numbers, booleans, nulls) and only converts string scalars.
Conversion details.
The tool parses the YAML, identifies all string scalars, and re-serializes them in the target style. Comments are preserved. Non-string values (numbers, booleans, nulls, arrays, objects) are not affected. If a string needs escaping in the target style (e.g., a single quote inside a single-quoted string), the tool handles the escaping automatically.
Quoting pitfalls in practice.
One of the most common YAML mistakes is assuming that a value like yes or no is a string. In unquoted style, YAML 1.1 interprets these as boolean true and false. The same applies to true, false, null, and even numeric patterns like 1e3. If your configuration expects the literal string "yes", you must quote it: "yes" or 'yes'. This tool can convert all values to a quoted style to avoid these type coercion surprises.
Another pitfall is colons in plain strings. A value like http://example.com is valid as a plain string if it doesn't start with a special character, but edge cases exist where YAML parsers misinterpret colons followed by spaces. Quoting eliminates ambiguity entirely. When in doubt, quote it.
Enforcing a consistent style.
Teams that work on shared YAML files — Docker Compose stacks, Kubernetes manifests, CI/CD configs — benefit from enforcing a single quoting convention. A consistent style reduces merge conflicts because every contributor's file has the same structure, making diffs smaller and more meaningful. Pick a style, document it in your project's contributing guide, and run this tool before committing to verify compliance.
Some linters and formatters like yamllint and Prettier can enforce quoting rules automatically, but they may reformat the entire file. This tool gives you fine-grained control: paste a snippet, pick a style, and see the converted output without touching the rest of the file. It's ideal for incremental adoption in large codebases.
Multi-line and special characters.
YAML supports multi-line strings with block scalars (| for literal, > for folded), which are not affected by quote-style conversion because they're not quoted in the source. Double-quoted strings are the only style that supports escape sequences like \n and \t. If you need literal newlines in a single-quoted string, you must use a block scalar instead.
Special characters like # (comment), : (mapping), and { } (flow mapping) are safe inside double-quoted strings but can cause parse errors in plain strings. This tool handles these cases by selecting the appropriate style when converting and adding escape sequences where necessary.
FAQ
How do I convert single quotes to double quotes in a YAML file?
In `ruamel.yaml`, load with `Loader=ruamel.yaml.Loader`, set `preserve_quotes=False`, and dump — but no built-in 'swap quotes' option exists in most tools.
How do I bulk-quote all string values in YAML?
Use `yq -I=0 '. | with_entries(.value style="double")' file.yaml` or `prettier` with `singleQuote: false` configured — both will quote loose strings.
Why does YAML auto-quote some values but not others?
YAML 1.2 quotes only when needed to avoid ambiguity: `yes`, `no`, `true`, `false`, `null`, numbers, and reserved chars need quoting to stay strings.
How do I remove unnecessary quotes from YAML values?
Run the file through `prettier` or `yq` with default settings — both will strip quotes from strings that don't need them for safety.
How do I force all string values to use single quotes in YAML?
Prettier with `"singleQuote": true` in `.prettierrc` will use single quotes; or use a `ruamel.yaml` post-processing script that walks scalars and sets `style='"'`.