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.
com.typesafe:config is JVM-only — it reaches for java.io, the classpath,
java.util.regex, and java.time — which leaves Scala.js and Scala Native with no good way to
read a .conf file. hocon fills that gap: the whole library is plain Scala 3 in a shared source
set, with no java.* imports and no regex engine in its core, 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). - Includes —
include "other.conf"(andfile/url/classpath/requiredforms) behind a pluggable, per-platformConfigSource. - A typed decoder —
config.as[A]maps a document onto a case class, with automaticMirror-derived decoders for nested case classes,Option,List, andMap. - Full path expressions and array append — quoted path segments,
+=, and self-referential substitutions, conformant with the HOCON spec. - An i18n sidecar —
Messageswith placeholder interpolation.
Every phase on the roadmap is complete.
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.