Generate Java files with the JSON to properties converter
The JSON to properties converter flattens a JSON object into key=value lines that java.util.Properties, Spring Boot and Java resource bundles can load. Nested keys are joined with dots, and every value is escaped so that it reads back exactly as written.
Typical uses include generating application.properties from a JSON settings export, creating messages_de.properties from a translation service that delivers JSON, and feeding values into build tools such as Maven or Gradle that read properties files.
Example
Input:
{
"app": { "name": "Acme Shop", "debug": false, "port": 8080, "greeting": "Grüße" },
"db": { "url": "jdbc:mysql://localhost:3306/acme?useSSL=false" },
"features": ["search", "checkout"],
"key with space": " leading",
"multi": "a\nb",
"note": null
}
Output with key.0, key.1:
app.name=Acme Shop
app.debug=false
app.port=8080
app.greeting=Gr\u00fc\u00dfe
db.url=jdbc:mysql://localhost:3306/acme?useSSL=false
features.0=search
features.1=checkout
key\ with\ space=\ leading
multi=a\nb
note=
Array keys option
- key.0, key.1 treats indexes like any other key segment. Choose it for generic tools and for bundles that are read by simple dotted-key lookups.
- key[0], key[1] (Spring) writes
spring.profiles.active[0]=dev. Spring Boot's relaxed binding maps these to aListin a@ConfigurationPropertiesclass, so pick this forapplication.properties.
Reading the generated file in Java and Spring
Plain Java loads the output with java.util.Properties. Every value comes back as a string, so numbers and booleans need converting:
Properties props = new Properties();
try (InputStream in = Files.newInputStream(Path.of("app.properties"))) {
props.load(in);
}
String name = props.getProperty("app.name"); // "Acme Shop"
int port = Integer.parseInt(props.getProperty("app.port")); // 8080
In Spring Boot, drop the file in src/main/resources as application.properties and bind a whole prefix at once with @ConfigurationProperties(prefix = "app") on a class or record with name, debug and port fields; Spring handles the type conversion. Keep in mind that Properties does not remember line order, so a file written back by Java code may list keys differently from the converter's output.
Escaping rules
- Non-ASCII characters become
\uXXXXescapes (ü→\u00fc).Properties.load(InputStream)reads files as ISO-8859-1, so escaping keeps accented text intact on every Java version. - Spaces,
=,:,#and!in keys are backslash-escaped, since they would otherwise end the key or start a comment. - A leading space in a value is escaped as
\; Java strips unescaped leading whitespace. - Line breaks and tabs become
\nand\t, and backslashes are doubled, so Windows paths survive. - Characters such as
=and:in values are left alone, because only the first unescaped separator matters. That keeps JDBC URLs readable.
Edge cases
nullbecomes an empty value (note=);Propertieshas no null.- Empty objects and arrays are written as
{}or[]text. - Numbers and booleans are written as text; Spring converts them to the target type when binding.
For Spring projects that prefer YAML, convert with JSON to YAML instead. To read a properties file back into JSON, use Properties to JSON.
Privacy
Everything runs in your browser; your JSON is not sent to a server.