What you can do here
| Button | What it does |
|---|---|
| Validate YAML | Checks the YAML and re-indents it, or shows the line and column of the first error |
| YAML to JSON | YAML → JSON. A file with several --- documents becomes a JSON array |
| Convert to YAML | JSON or XML → YAML |
| Property to YAML | key=value lines from a .properties file → nested YAML |
| YAML to Property | Nested YAML → flat key=value lines |
Only need one conversion? The YAML to JSON converter and the JSON to YAML converter do exactly that with one click.
Finding YAML errors
YAML errors are hard to spot because the problem is often whitespace. Paste the file and click Validate YAML: the line with the error turns red and the message says what the parser expected. Common causes:
- A tab used for indentation. YAML only allows spaces.
- A key indented differently from its siblings, so the parser can't tell which block it belongs to.
- "mapping values are not allowed here": a value contains
:and needs quotes, for exampletitle: "Note: read me". - The same key twice in one block. Many parsers silently keep the last one; this validator reports it.
When the YAML is valid, it is rewritten with consistent two-space indentation. Comments are not kept in the rewritten version, so keep your original if it has comments you need.
Spring Boot: application.properties to application.yml
Spring Boot reads both files the same way. Dotted keys in a properties file turn into nested blocks in YAML:
server.port=8080
spring.datasource.url=jdbc:postgresql://localhost/app
spring.datasource.username=app becomes
spring:
datasource:
username: app
url: jdbc:postgresql://localhost/app
server:
port: 8080 The order of keys can change along the way. Spring doesn't care about order, but reorder by hand if you want the file to read top-down. Comments in the properties file are not carried over.
Going the other way, lists become numbered keys: a YAML list under hosts: turns into hosts[0]=… and hosts[1]=…, which is the form Spring expects in a properties file.
Why some keys get quotes
Convert {"country": "no", "y": 2, "on": true} and you'll get:
country: "no"
"y": 2
"on": true The quotes are deliberate. Older YAML parsers read words like y, n, yes, no, on and off as true or false. Without the quotes, the country code for Norway would turn into false. Quoting keeps them as plain text in every parser.
YAML indentation in short
- Indent with spaces, never tabs.
- Children are indented further than their parent. Two spaces is the usual choice.
- A list item starts with a dash and a space:
- item. - Strings rarely need quotes, except when they contain
:, start with a character like*,&or#, or look like a number or boolean.
Frequently asked questions
Is JSON valid YAML?
Yes. YAML 1.2 is a superset of JSON, so any JSON document is also valid YAML. That is also why converting JSON to YAML never loses data. The reverse isn't true: YAML has comments, anchors and multiple documents per file, which JSON can't express.
Should I use application.properties or application.yml?
Both behave the same at runtime. YAML is easier to read when many settings share a prefix. Properties files are easier to override one line at a time and to search with grep.
Does the converter keep comments?
No. JSON has no comments to begin with, and comments in a properties file or a YAML file are dropped when it is converted or re-indented. Add them back by hand if you need them.
Can it convert YAML with several documents?
Yes. When a file has several documents separated by ---, Validate YAML keeps them as separate documents and YAML to JSON turns them into a JSON array with one item per document.