Is there a Java library similar to libconfig for C++, where the config file is stored in a JSON-like format that can be edited by humans, and later read from the program?
I don't want to use Spring or any of the larger frameworks. What I'm looking for is a small, fast, self-contained library. I looked at java.util.Properties
, but it doesn't seem to support hierarchical/nested config data.
I think https://github.com/typesafehub/config is exactly what you are looking for. The format is called HOCON for Human-Optimized Config Object Notation and it a super-set of JSON.
Examples of HOCON:
HOCON that is also valid JSON:
HOCON also supports standard properties format, so the following is valid as well:
One of the features I find very useful is inheritance, this allows you to layer configurations. For instance a library would have a
reference.conf
, and the application using the library would have anapplication.conf
. The settings in theapplication.conf
will override the defaults inreference.conf
.Standard Behavior for loading configs: