Skip to content

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.

Terminal window
go install github.com/o3co/hocon2/cmd/hocon2json@latest
go install github.com/o3co/hocon2/cmd/hocon2yaml@latest
go install github.com/o3co/hocon2/cmd/hocon2toml@latest
go install github.com/o3co/hocon2/cmd/hocon2properties@latest

Pre-built binaries for Linux, macOS and Windows on amd64 and arm64 are attached to each release.

Terminal window
# A file
hocon2json app.conf
# Or a pipe
cat app.conf | hocon2yaml
# Write somewhere, without clobbering by accident
hocon2json -o output.json app.conf
hocon2json -o output.json -overwrite app.conf
# Formatting
hocon2json -compact app.conf
hocon2json -indent 4 app.conf

Each command is a separate binary rather than a subcommand, which keeps them composable in a Makefile or a CI step without a wrapper.

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:

Terminal window
hocon2json -validate config/prod.conf