Flatten YAML with the YAML to properties converter
The YAML to properties converter walks a YAML document and writes one key=value line for every leaf value, joining parent keys with dots. It is the fastest way to see the full property name of a deeply nested setting, to pass values as -D system properties or environment overrides, or to move a Spring Boot project from application.yml back to application.properties.
Example
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://db:3306/shop
password: ${DB_PASS}
profiles:
active: [dev, metrics]
app:
motd: |
Welcome
to Acme
owners:
- name: Ann
email: ann@example.com
empty: null
Output with Spring-style array keys:
server.port=8080
spring.datasource.url=jdbc:mysql://db:3306/shop
spring.datasource.password=${DB_PASS}
spring.profiles.active[0]=dev
spring.profiles.active[1]=metrics
app.motd=Welcome\nto Acme\n
app.owners[0].name=Ann
app.owners[0].email=ann@example.com
app.empty=
Options explained
Array keys controls how list items are numbered. key[0] is the default because it is what Spring Boot's relaxed binding expects for lists and lists of objects, as in app.owners[0].name. key.0 suits generic tools that only understand dotted names; the example list would become spring.profiles.active.0=dev.
Why flatten YAML?
Nested YAML is pleasant to edit but awkward to override. Command-line flags such as --server.port=9090, test annotations like @TestPropertySource and many deployment dashboards all expect the full dotted name. Flattening the file once gives you a complete list of those names to copy from.
If both files exist in a Spring Boot project
Spring Boot reads application.properties and application.yml from the same locations, and when both files are present in one location, the .properties values take precedence. After converting, delete or rename the YAML file so nobody edits a file whose values are silently overridden.
To confirm that every property kept its name, compare the output with what the running application reports: with Spring Boot Actuator enabled, the /actuator/env endpoint lists each loaded property under the same dotted, indexed names this converter produces, for example spring.profiles.active[0].
Edge cases
- Block scalars (
|and>) are escaped into one line with\n, including the trailing newline that|keeps. - Placeholders such as
${DB_PASS}are copied as text; Spring resolves them the same way in both formats. - null values become empty (
app.empty=). - YAML 1.2 rules apply. Dates like
2024-05-01and words likeyesoronstay plain text rather than being turned into timestamps or booleans. - Merge keys (
<<: *defaults) are not expanded; the output contains a literal<<segment. Inline the shared values before converting. - Multi-document files separated by
---are rejected. Split profile sections into separate inputs and convert each one. - Non-ASCII characters are written as
\uXXXXescapes so the file loads correctly withProperties.load.
Going the other way? Use Properties to YAML. If your YAML does not parse, check it first with the YAML validator, or convert it to JSON with YAML to JSON to inspect the structure.
Privacy
Your YAML is converted in the browser and never uploaded.