Skip to content

Format adapters

A real repository rarely holds one configuration format. All four implementations can ingest foreign formats into the same configuration object, so the code reading a value does not have to know which file it came from.

Supported everywhere: environment variables (bulk mount and .env files), Java .properties, JSON with comments (JSONC/JSON5), TOML and YAML. Plain JSON needs no adapter — HOCON is a superset of it.

The mechanism differs per language, but the goal is the same everywhere: the core parser takes on no dependency because an adapter exists, and you pay for a decoder only if you use it.

Subpath exports, with the decoder as an optional peer dependency.

Terminal window
npm install @o3co/ts.hocon smol-toml # only if you need TOML
import { fromToml } from '@o3co/ts.hocon/adapters/toml'

Ingestion happens at the value level. A foreign document is decoded by its own library into a tree, and that tree is handed to the configuration model directly. It is never rendered as HOCON text and re-parsed.

The consequence is worth stating plainly: nothing inside a TOML or YAML file becomes HOCON syntax. A string that reads ${HOME} in a YAML document stays that literal string. It does not become a substitution. The same is true of +=, of concatenation, and of include. Ingested trees arrive fully resolved — they can be the target of a substitution written in a HOCON file, but they never contain one.

Foreign-format behaviour is specified as F-items in format-ingestion-mapping.md, in the same style as the specification checklist. Errors raised by the adapters cite the item number, so an error like (spec F1.6) leads directly to the rule that produced it.

These items are deliberately kept out of the compliance percentages. Lightbend’s specification says nothing about ingesting TOML, so there is no reference implementation to be measured against — for everything except .properties there is no oracle at all. An F-item is a decision this project made and then held four implementations to, verified by differential fixtures rather than by an external authority. Counting those as “specification compliance” would be inventing credit.