2 ms·
I like HOCON, although it's a bit obscure. It's a JSON syntax superset with the same data model, designed for human written config. It doesn't have schema supp
by mike_hearn 2y ago
I like HOCON, although it's a bit obscure. It's a JSON syntax superset with the same data model, designed for human written config.
It doesn't have schema support however you arguably don't need one, because the software that reads the config specifies the type of keys when the value is read and casting takes place then. If the software expects a string, it reads the value as a string, if it expects a number it's parsed as a number and so on.
HOCON has hierarchical merging, include files, a more convenient syntax, ability to read environment variables, substitutions, comments and a few other convenience features. In Conveyor, a tool for packaging desktop apps I wrote that uses it, it's also extended so you have "hash-bang includes". Those are includes that specify a program to run instead of a file, the output is then included and parsed at that point. This lets you escape from declarative config to a fully dynamic computation if you need to. You can disable this feature with a command line flag if you don't trust the config you're parsing (and also env var substitution).
You can also render the whole config to regular JSON if you need to.
I find that set of features to nicely balance config complexity with read/writeability. The main issue is that the main library is not well maintained, and the best implementation is for the JVM. You could give it a C API these days with Native Image but nobody has.
Main downside vs yaml is that IDEs and editors can use YAML schemas to give auto-completion whereas they don't do that for HOCON.
- hollerith 2y agoDoes the HOCON parser complain and refuse to proceed if it encounters a comma right before a closing curly brace like the JSON parsers with which I've interacted?
- mike_hearn 2y agoNo no. The syntax is designed for usability, training commas are fine. There's a little tutorial here, with a slider that shows how you can start with json and transform it. The right hand side is valid HOCON at every step: https://conveyor.hydraulic.dev/15.0/configs/hocon/ https://conveyor.hydraulic.dev/15.0/configs/hocon/