Convert JSON to properties files
A practical review of converting JSON to .properties files: what flattening changes, what gets lost, how encoding and escaping affect readability, and when to keep JSON instead.
Turning a JSON document into a .properties file is a common step when configuration written for one system has to feed a Java application, a Spring Boot service or a build tool that expects flat key-value pairs. The conversion looks simple, but it is not a neutral reformat. Structure, data types and some characters are rewritten. Whether the result is usable depends on how your target program reads it. This review explains what changes, what can go wrong, and when the conversion is worth doing.
A note on scope: no specific converter was tested for this article, and no measurements or tool comparisons are offered. The behavior described below comes from the published conventions of the JSON and Java properties formats. Any particular tool may follow those conventions differently, so check its output against the points raised here.
Is converting JSON to properties suitable for your use?
It is a good fit when the JSON is configuration-shaped. That means mostly nested objects whose leaves are strings, numbers or booleans, and a consumer that reads properties natively. The main benefit is direct compatibility: Java's Properties class, resource bundles and Spring's property binding can load the file without a JSON parser or custom mapping code.
The decisive tradeoff is that the properties format is flat and untyped. Every value becomes a string, nesting becomes a naming convention, and arrays depend on whatever indexing scheme the converter picks. If the consumer does not interpret those conventions the same way, the meaning of the data changes even when every character transfers correctly.
Keep the data as JSON, or choose a structured format such as YAML, in these situations:
- The data contains deeply nested arrays of objects, which flatten into long, hard-to-maintain indexed keys.
- The consumer needs to tell a number, boolean or null apart from a string that happens to look like one.
- You expect to convert back to JSON later and need an exact round trip.
- Keys in the JSON already contain dots or brackets, which collide with the flattening convention.
- People will mostly read and edit the file by hand and need to see its structure at a glance.
What the conversion actually changes
Conversion changes both the stored text and how it is organized. Unlike a cosmetic formatting step, it rewrites the data into a different model. There are four main mechanisms.
Flattening nested structure
Nested objects are collapsed into dotted key paths. The object {"server": {"port": 8080}} becomes the single line server.port=8080. The hierarchy survives only as a naming pattern, and only programs that split keys on dots can rebuild it.
Representing arrays
The properties format has no array type, so converters invent one. Common styles include bracket indexes (features[0]), dotted indexes (features.0) and comma-joined values (features=search,export). Spring Boot's documentation describes the bracket-index style for binding lists, but other consumers may expect something else. Check that the style a converter produces matches what your application reads.
Losing data types
Properties values are always text. The JSON number 8080, the boolean false and the string "false" all end up as identical text in the output. JSON null has no standard equivalent. Converters may write an empty value, write the word null, or drop the key, and these choices mean different things to the program reading the file. Empty objects and empty arrays usually disappear entirely, because they have no leaf values to emit.
Escaping and encoding
Properties syntax treats some characters specially. A backslash starts an escape sequence, and a backslash at the end of a line continues the value onto the next line. A line starting with # or ! is a comment. In keys, =, : and whitespace act as separators, so they must be escaped to appear literally. Whitespace at the very start of a value is discarded unless escaped. Converters also commonly rewrite characters outside ASCII as \uXXXX sequences, as explained in the encoding section below.
A worked example
This input covers the cases above: nesting, an array, a non-ASCII string, a boolean and a backslash.
{
"server": { "port": 8080, "host": "localhost" },
"features": ["search", "export"],
"greeting": "Grüße, world",
"debug": false,
"path": "C:\\temp"
}
A converter using bracket-indexed arrays and ASCII-safe escaping would produce output like this:
server.port=8080
server.host=localhost
features[0]=search
features[1]=export
greeting=Gr\u00fc\u00dfe, world
debug=false
path=C:\\temp
Checking this output against the rules above:
- The JSON string "C:\temp" decodes to C:\temp, with a single backslash. Because properties also uses the backslash as an escape character, that backslash has to be written as \ again in the output. A converter that copies the raw JSON text without decoding first, or one that forgets to re-escape, will produce a wrong path.
- ü is U+00FC and ß is U+00DF, so the \u escapes are correct. Both characters also exist in ISO-8859-1, so some converters leave them unescaped. That is valid only if the reader uses a matching encoding.
- The values 8080 and false are now plain text. Any typing happens in the program that reads the file, not in the file itself.
- The key order follows the input here, but the format does not guarantee order. Java's Properties.store, for example, does not keep insertion order.
Flattening collisions
Flattening can merge keys that were separate in the JSON. In the following input, the literal key "a.b" and the nested path a → b both flatten to the same property name.
{ "a.b": 1, "a": { "b": 2 } }
Two lines with the key a.b result, or the converter silently keeps only one of them. When a properties file contains duplicate keys, Java's loader keeps the last one, so one value is lost without any error. A careful converter should detect and report this kind of collision. Whether a given tool does so has to be checked case by case.
Will the result stay readable and usable after copying or sharing?
Character encoding
Encoding is the most frequent cause of broken properties files. The encoding Java uses depends on the loading method:
- Properties.load with an InputStream reads ISO-8859-1.
- Properties.load with a Reader uses whatever charset the Reader was created with.
- Since Java 9, PropertyResourceBundle reads UTF-8 by default and falls back to ISO-8859-1 if the file is not valid UTF-8.
Because of these differences, a UTF-8 file containing raw accented characters can load correctly in one code path and show garbled text in another. Escaping every non-ASCII character as \uXXXX avoids the problem entirely, since pure ASCII reads the same under every one of these encodings. If you do not control how the file will be loaded, the escaped form is the safer choice.
Readability, search and editing
Escaping has a human cost. A line such as greeting=Gr\u00fc\u00dfe is harder to read and edit than the original text, and a plain text search for Grüße will not find it. Screen readers and other assistive technology read the escape sequence literally rather than the intended character, so translated strings in escaped form are hard to review by any means other than a tool that decodes them. For teams maintaining localized text by hand, a UTF-8 properties file loaded through a UTF-8-aware path, such as resource bundles on Java 9 and later, is usually more practical. Confirm that loading path before you rely on it.
Copy and paste
Properties files are plain text, so copying them between editors, terminals and chat tools generally keeps the characters intact. A few details can still change in transit:
- Trailing whitespace in a value is significant in properties files, and some editors or paste targets strip it.
- A value ending in a lone backslash is treated as a line continuation, so an accidental edit there joins two lines into one.
- Smart-quote or autocorrect features in word processors and some messaging apps can replace straight characters with typographic ones.
- Windows and Unix line endings are both accepted by Java's loader, but other tools that read the file may be stricter.
No specific editor, paste destination or screen reader was tested for this article. Check the file in the tools your team actually uses rather than assuming that one clean result applies everywhere.
Converting back to JSON
A reverse conversion cannot reliably rebuild the original. It has to guess whether 8080 was a number or a string, whether features[0] was an array, and whether a missing key was ever there. If you need JSON again later, keep the original JSON as the source of truth and generate the properties file from it, rather than editing the properties file and converting it back.
Checklist for evaluating a converter
| Check | What to look for |
| Array style | Matches the indexing your application binds (for example, bracket indexes for Spring Boot lists) |
| Null and empty values | Documented, consistent handling of null, empty strings, empty objects and empty arrays |
| Key collisions | Warns or fails when flattened keys clash, instead of silently dropping one |
| Escaping | Correctly escapes backslashes, separators in keys, leading whitespace and comment characters |
| Encoding | Lets you choose between \uXXXX escaping and raw UTF-8, matching how the file will be loaded |
| Ordering | Keeps or sorts keys predictably, so changes are easy to review in version control |
| Data handling | If the tool runs online, read its stated data practices before pasting secrets; do not judge them from the site's appearance |
Bottom line
Converting JSON to properties works well for flat or moderately nested configuration that a Java or Spring program will read. The format conversion itself is reliable when escaping and encoding are handled correctly. The real risk is meaning: types, nulls, array structure and colliding keys can change or disappear without any error. Run a small sample that covers those cases through your chosen converter and load the result in your target application before trusting it with a full configuration. If the data depends on structure or types, keep it in JSON or YAML.