hocon2 CLI
hocon2 is for when the tool consuming your configuration cannot be changed. Author in HOCON,
convert at build or deploy time, hand the result to something that only speaks JSON, YAML,
TOML or Java .properties. It is built on go.hocon, so the
conversion is the same parser the library uses.
Install
Section titled “Install”go install github.com/o3co/hocon2/cmd/hocon2json@latestgo install github.com/o3co/hocon2/cmd/hocon2yaml@latestgo install github.com/o3co/hocon2/cmd/hocon2toml@latestgo install github.com/o3co/hocon2/cmd/hocon2properties@latestPre-built binaries for Linux, macOS and Windows on amd64 and arm64 are attached to each release.
# A filehocon2json app.conf
# Or a pipecat app.conf | hocon2yaml
# Write somewhere, without clobbering by accidenthocon2json -o output.json app.confhocon2json -o output.json -overwrite app.conf
# Formattinghocon2json -compact app.confhocon2json -indent 4 app.confEach command is a separate binary rather than a subcommand, which keeps them composable in a
Makefile or a CI step without a wrapper.
Both directions
Section titled “Both directions”| To another format | From another format |
|---|---|
hocon2json |
json2hocon |
hocon2yaml |
yaml2hocon |
hocon2toml |
toml2hocon |
hocon2properties |
properties2hocon |
The reverse commands read a foreign file, build a value tree and render idiomatic HOCON — the migration path for a repository that already has a hundred YAML files.
Foreign data stays data on the way in. A ${...} in an input value is emitted literally rather
than becoming a substitution, and types survive the round trip: a Properties value or a JSON
string "8080" is quoted on output so it re-parses as a string and not as a number.
-validate parses without emitting, so a malformed configuration fails the build rather than
the deployment:
hocon2json -validate config/prod.confReading further
Section titled “Reading further”- hocon2 on GitHub — full flag reference
- go.hocon — the parser underneath
- Format adapters — the same conversions, in-process, from any of the four languages