How to convert JSON to properties
A .properties file is a flat list of key=value lines. JSON nests objects inside objects. To convert json to properties, the tool walks the JSON and joins the names on the way down with dots, so server with a port inside it becomes server.port=8080. Strings, numbers and booleans become the value after the equals sign.
Take this JSON:
{
"server": { "port": 8080 },
"app": {
"cors": { "origins": ["https://example.com", "https://admin.example.com"] },
"timeout": 2.5
}
}It becomes:
server.port=8080
app.cors.origins[0]=https://example.com
app.cors.origins[1]=https://admin.example.com
app.timeout=2.5Everything runs in your browser and the text is not uploaded. Configuration often holds passwords, so that matters. See the Privacy Policy.
JSON to application.properties for Spring Boot
Spring Boot reads application.properties, and a JSON file is easy to write while a .properties file is what many teams keep in version control. Index arrays, the default here, are the form Spring uses to bind a list, so app.cors.origins[0] and app.cors.origins[1] fill a List in your configuration class.
Current Spring Boot versions read application.properties as UTF-8, so leave the \uXXXX option off and keep real characters. If you go the other way, Properties to JSON rebuilds the nested object, and YAML to Properties does the same job for application.yml.
How arrays are written
- Index:
list[0]=aandlist[1]=b. This is the Spring Boot style and the default. - Dot index:
list.0=aandlist.1=b. Some libraries and frameworks read this form. - Comma separated:
list=a,bon one line, as long as every item is plain text without commas, spaces at the edges or line breaks. Otherwise that list falls back to index keys and the notes say so.
An array of objects always uses keys under the index, so servers[1].host is the host of the second server. An empty array is written as an empty value, such as servers[1].tags=, and is listed in the notes.
Escaping in properties files
A value needs fewer escapes than a key. A backslash is doubled, a line break becomes \n, a tab becomes \t and a leading space is protected. In a key, spaces, equals signs and colons are escaped too, and a key that starts with # or ! is escaped so it is not read as a comment.
This is why the path C:\temp\files comes out as C:\\temp\\files. Java reads the doubled backslash back as one. Characters beyond ASCII, such as the é in Café or an emoji, stay as they are, unless you turn on Escape non-ASCII, which writes each UTF-16 unit as a \uXXXX escape that any Java version can read.
Null values, empty objects and odd keys
A properties file has no null. Choose between an empty value (key=), leaving the key out, or the text null. An empty object or list becomes an empty value. A key that already holds a dot, such as com.example in logging levels, is kept as written, and the notes warn you that Spring reads it as a path.
If a top-level list or a single value is pasted, the keys start with an index or with the word value. Add a key prefix to give them a name. JSON numbers with more than 15 digits are rounded by JSON parsing itself, and the notes flag them so you can check the result.
Limits and related tools
Comments cannot be kept, because JSON has none. Object keys that are whole numbers are listed first in ascending order, because that is how JavaScript orders them when it parses JSON. A one-item list written as a comma line reads back as a plain string. The tool does not split Spring profiles and does not read YAML. For YAML input use YAML to Properties, and to move JSON into another config format use JSON to YAML.