What this is
hocon is a pure-Scala implementation of HOCON
(Human-Optimized Config Object Notation) — the comfortable, JSON-superset config format
popularized by Lightbend’s com.typesafe:config.
The reference implementation is excellent, but it is JVM-only: it reaches for
java.io, the classpath, java.util.regex, and java.time. That leaves Scala.js and
Scala Native with no good way to read a .conf file. hocon fills that gap — the parser and
the untyped Config API are written in plain Scala 3 and live in a shared source set, so
the same code runs on all three platforms.
import io.github.edadma.hocon.*
val config = Hocon.parse("""
en {
greeting = "Hello, world"
nav { home = "Home", about = "About" }
cart.items = "{count} items" # path-expression key
}
""")
config.getString("en.greeting") // "Hello, world"
config.getString("en.nav.home") // "Home"
config.hasPath("en.missing") // false
Why HOCON for i18n
HOCON is a natural fit for internationalization message files: nested, commented,
human-friendly, and far less noisy than JSON. hocon ships a small Messages helper for the
{name} placeholder pattern, and Phase 2’s merging makes a base locale with per-locale
overrides a one-liner.
val base = Hocon.parse("""greeting = "Hello", farewell = "Goodbye"""")
val fr = Hocon.parse("""greeting = "Bonjour"""")
val messages = Messages(fr.withFallback(base))
messages("greeting") // "Bonjour" (translated)
messages("farewell") // "Goodbye" (from the base locale)
What you get today
- A full lexer and parser — comments (
#and//), quoted strings with escapes, triple-quoted multi-line strings, numbers, booleans, null, nested objects, arrays, and path-expression keys (a.b.c = v). - An untyped
ConfigAPI — typed getters (getString,getInt,getBoolean,getConfig,getList, …) with*Optvariants,hasPath, and clear exceptions. - Object merging and fallback —
withFallbackandHocon.load, with recursive object merge and last-wins layering. - Substitutions —
${path}and optional${?path}, resolved against the merged root, with environment fallback and cycle detection. - Value concatenation — joining strings, arrays, and objects written side by side
(
"http://"${host},[1] [2],${defaults} { … }). - Durations and sizes —
getDuration(10s,5 minutes) andgetBytes(512K,10MB). - An i18n sidecar —
Messageswith placeholder interpolation.
include directives and a typed case-class decoder are on the roadmap.
Where to go next
- Getting Started — add the dependency and parse your first config.
- Guide — the HOCON format hocon supports, merging and fallback, and the roadmap.
- Reference — the
ConfigAPI and theMessageshelper.