vs HOCON: Data or Config Language
One format describes values. The other also computes them.
HOCON, the format of Lightbend Config, adds includes, substitutions, object merging and unit-aware values to JSON. JSON5 adds comments, trailing commas and ECMAScript-style literals, then stops.
This page reads the HOCON specification closely, runs the same inputs through the Java reference library, two npm parsers, a Python parser and json5, shows where they disagree, and explains when the extra machinery earns its cost.
TL;DR: Use HOCON when a JVM stack already reads it, or when you need layered files, references and environment overrides inside the config itself. Use JSON5 when a file should mean exactly what it says, parse the same way everywhere, and leave merging to a few lines of your own code. HOCON accepts ordinary JSON, but it is not a superset of JSON5: single-quoted strings load with the quotes still inside them.
What HOCON Is
HOCON stands for Human-Optimized Config Object Notation. It is defined by HOCON.md in the repository of the Lightbend Config library (Maven coordinates com.typesafe:config, still widely called Typesafe Config). The document describes itself as an informal specification. Its stated goal is to keep JSON's semantics, meaning the tree structure, the set of types and the string escaping, while making files more convenient to edit by hand.
The wish list in that document goes well past punctuation: less pedantic syntax, references from one setting to another, inclusion of other files, a mapping to Java system properties, access to environment variables, and comments. It also asks that the format be deterministic rather than heuristic, so that invalid files produce errors. And it is candid about the price: HOCON is "significantly harder to specify and to parse than JSON," moving work from the person maintaining the file to the program reading it.
JSON5 has a much smaller ambition. The 1.0.0 specification, dated March 2018, extends JSON with syntax taken from ECMAScript 5.1. A JSON5 document is a single literal value. Nothing in it refers to anything else, reads the environment or opens another file. The design rationale page covers why.
| Fact | HOCON | JSON5 |
|---|---|---|
| Defining document | HOCON.md, informal | Specification 1.0.0, March 2018 |
| Reference implementation | com.typesafe:config (Java, no dependencies) | json5 (JavaScript) |
| Latest release seen | 1.4.10, November 6, 2026 | 2.2.3, December 31, 2022 |
| License of that library | Apache 2.0 | MIT |
| Usual file extension | .conf | .json5 |
| Media type named by the spec | application/hocon | None named by the specification |
Lightbend's README says the company considers the library feature complete: it will keep it working with future JVM versions but will rarely make other changes. The library supports Java 8 and later and loads three formats: Java properties, JSON and HOCON. The README's own version snippet still showed 1.4.4 when we checked, so read Maven Central for the current number.
The Same Config in Both Formats
This HOCON file shares defaults, lets an environment variable override a port, extends a list and assembles a URL:
# service settings
defaults {
host = localhost
timeout = 30 seconds
max-upload = 10MiB
tags = [web]
}
http-port = 8080
http-port = ${?SERVICE_PORT}
service = ${defaults} {
name = api
port = ${http-port}
}
service.tags = ${defaults.tags} [internal]
url = "http://"${defaults.host}":"${http-port}
log.level = info
log.file = nullLoaded with com.typesafe:config 1.4.10 on Java 21, resolved, and printed as formatted JSON, with SERVICE_PORT unset (line breaks inside the short arrays condensed):
{
"defaults" : {
"host" : "localhost",
"max-upload" : "10MiB",
"tags" : ["web"],
"timeout" : "30 seconds"
},
"http-port" : 8080,
"log" : { "file" : null, "level" : "info" },
"service" : {
"host" : "localhost",
"max-upload" : "10MiB",
"name" : "api",
"port" : 8080,
"tags" : ["web", "internal"],
"timeout" : "30 seconds"
},
"url" : "http://localhost:8080"
}Running again with SERVICE_PORT=9000 changed url to "http://localhost:9000" and both port settings to "9000", now a string, because environment variables always arrive as text. The library's typed getters convert it when the application asks for a number.
The JSON5 file with the same effective service settings has no references, so the shared values are written once, where they are used, and the override moves into code:
{
// service settings
service: {
name: 'api',
host: 'localhost',
port: 8080, // the application may override from SERVICE_PORT
timeoutMs: 30000,
maxUploadBytes: 10485760,
tags: ['web', 'internal'],
},
log: { level: 'info', file: null },
}The numbers 30000 and 10485760 are exactly what getDuration in milliseconds and getBytes returned for the HOCON values.
Syntax Compared
| Feature | JSON5 | HOCON |
|---|---|---|
| Comments | // and /* */ | // and #; no block comments |
| Root braces | Required for an object | Optional |
| Key separator | : | :, =, +=, or nothing before { |
| Commas | Required; one trailing comma allowed | A newline can replace them; one trailing comma ignored |
| Unquoted keys | ECMAScript identifier names | Path expressions: a.b.c nests, spaces are kept |
| Unquoted string values | ||
| Single-quoted strings | ||
| Multiline strings | Backslash line continuation | """triple quotes""", taken literally |
| Numbers | JSON plus hex, .5, 5., +1, Infinity, NaN | JSON number forms only |
| Duplicate keys | Names should be unique; behavior is left open, and json5 2.2.3 keeps the last | Objects merge; otherwise the last wins |
| References and environment | ${path}, ${?path} | |
| Includes | include statement |
Unquoted strings and concatenation
An unquoted HOCON string may not contain any of $ " { } [ ] : = , + # ` ^ ? ! @ * & \ or whitespace, may not contain //, and may not begin like true, false, null or a number. No escapes work inside it. Yet 30 seconds is one value, because adjacent simple values on a line are concatenated, keeping the whitespace between them. The same rule joins arrays with arrays and merges objects with objects. Concatenation never crosses a newline, and mixing an array with an object is an error.
That has a consequence people meet quickly: [ 1 2 3 4 ] is an array of one element, the string "1 2 3 4". Only commas or newlines separate elements.
Paths as keys
log.level = info is shorthand for log { level = info }. Unquoted dots always split the path, even inside things that look like numbers: 3.14 : 42 produces {"3":{"14":42}}. Quote a key that contains a real dot. In JSON5, a dotted key must be quoted and is one key; see the syntax reference.
Whitespace and multiline strings
HOCON treats the Unicode separator categories, the byte order mark and several ASCII control characters as whitespace, but only U+000A counts as a newline. Triple-quoted strings use every character literally, including indentation, and do not interpret Unicode escapes. Extra quotes at the end belong to the string: """foo"""" is foo", as in Scala.
Object Merging
Repeating a key is a feature. If both values are objects they merge recursively; otherwise the later one replaces the earlier. Because merging happens two values at a time, setting a non-object in between cuts the link, which is how you discard inherited defaults.
# merged: {"a":{"x":1,"y":2}}
a { x: 1 }
a { y: 2 }# reset: {"a":{"y":2}}
a { x: 1 }
a: null
a { y: 2 }Concatenation gives the common "inheritance" idiom, east = ${generic} { name = "east" }. The specification notes that its duplicate-key rule stays compatible with JSON only on the assumption that duplicate keys are invalid JSON in the first place.
For JVM applications the spec also describes a file hierarchy: every reference.conf on the classpath supplies library defaults, application.conf (or .json, or .properties) sits above it, and Java system properties override both. The library resolves the reference stack on its own first, so a substitution inside reference.conf cannot be satisfied only by the application file. The system properties config.file, config.resource and config.url replace the default application config.
Substitutions
A substitution copies a value from elsewhere in the tree, falling back to external sources such as environment variables. Six rules matter most:
- Paths are absolute, from the configuration root.
- Resolution is the last step, so references can point forward and see the final value.
b: ${a},a: 1,a: 2givesbthe value 2. ${x}that resolves to nothing is an error.${?x}makes the field vanish, or leaves an earlier value in place.- Nothing is substituted inside quotes. Write
${base}"/tasks", not"${base}/tasks". - A substitution standing alone keeps the target's type; concatenated, it becomes part of a string.
- Cycles are errors, except that a self-referential field such as
path: ${path} ["/usr/bin"]looks back to its previous value.
The last rule has sharp edges. s = ${d} { url = ${s.host} } fails in 1.4.10 with UnresolvedSubstitution: ${s.host} is reported as part of a cycle, because it points into the object still being defined. Move such derived values to a separate key, as the example above does.
Environment variables
The usual override is two lines, a default followed by key = ${?NAME}. Lookup is case-sensitive, even on Windows. Setting the same name to null in the config blocks the environment lookup. Related features go further:
a += bis defined asa = ${?a} [b].${NAME[]}collectsNAME_0,NAME_1and so on into a list until an index is missing. Release notes list environment list substitution under 1.4.6 (February 2026), so older versions and other parsers may not have it.- In the Java library,
-Dconfig.override_with_env_vars=truelets variables prefixedCONFIG_FORCE_override any key;_becomes a dot,__a hyphen and___an underscore.
Includes
include "defaults.conf"
include file("/etc/myapp/local.conf")
include classpath("module.conf")
include url("https://config.example.com/shared.conf")
include required(file("secrets.conf"))An include sits where an object field would, and the included file must contain an object. Its keys merge into the including object by the duplicate-key rules, so position matters: lines after the include override it. The behaviors to remember:
- A missing file is silently ignored unless wrapped in
required(). In our run,include "nothing.conf"followed bya: 1loaded cleanly; the required form raised an I/O error. - A bare quoted name is interpreted heuristically as a URL, an adjacent file or a classpath resource. Only this form resolves relative to the including file.
- A name without an extension may load
.properties,.jsonand.confand merge all that exist. - The argument must be one quoted string. No substitutions are allowed in it.
- A substitution inside an included file is tried first against the root of the included file, then against the root of the including configuration.
Security follows from this: a HOCON file can name local files and URLs for the parser to read, and can copy environment variables into values. Do not load HOCON from untrusted users with a full-featured loader, and be careful about printing a resolved config that may now hold secrets. The security tutorial covers the general rules for parsing input.
Durations, Periods and Sizes
HOCON has no duration or size type; the spec says the type system cannot be extended. 10ms and 512K are strings, and the specification recommends that a library interpret them when the application asks for a duration or a byte count. Unit names are case-sensitive.
| Family | Bare number means | Units |
|---|---|---|
| Duration | milliseconds | ns, us, ms, s, m, h, d and their long names such as minutes |
| Period | days | d, w, m or mo (months), y and long names |
| Bytes, powers of 1000 | bytes | kB, MB, GB through YB and long names |
| Bytes, powers of 1024 | bytes | K, k, Ki, KiB, M, m, Mi, MiB and so on |
Results from 1.4.10:
| Value | getBytes | Value | getDuration (ms) |
|---|---|---|---|
10K | 10240 | 500 | 500 |
10kB | 10000 | 10ms | 10 |
10KB | error: unit not recognized | 1m | 60000 |
1m | 1048576 | 2h | 7200000 |
1MB | 1000000 | 1w | error: weeks are a period unit |
Note 1m: one mebibyte as a size, one minute as a duration. The spec itself suggests avoiding single-letter size units if the ambiguity bothers you. Conversion also covers booleans: the typed getter accepted debug: yes as true and the string "42" as an integer. The recommended boolean words are true, yes, on, false, no and off. In JSON5, put the unit in the key (timeoutMs) or convert in your own code, and check types with schema validation.
Inputs That Surprise
Each HOCON result is real output from com.typesafe:config 1.4.10; \n marks a line break.
| Input | HOCON result | What happened |
|---|---|---|
debug: flase | {"debug":"flase"} | A typo is a valid string |
a: foo # bar | {"a":"foo"} | # starts a comment |
a: localhost, | {"a":"localhost"} | Trailing comma ignored |
a: true foo | {"a":"true foo"} | Concatenation turns a boolean into text |
a: 1.10 | {"a":1.1} | Rendered as a number, though getString returned 1.10 |
a: 0x1F | {"a":"0x1F"} | Not a JSON number, so a string |
a: 'hi' | {"a":"'hi'"} | Apostrophes are ordinary characters |
a: http://example.com | Parse error at : | : is forbidden unquoted, and // is a comment; quote URLs |
a: Infinity\nb: .5\nc: +1 | Parse error | + is reserved |
/* c */\na: 1 | Parse error | No block comments |
| An empty document | {} | Braces are implied |
The sharpest one for anyone mixing the two formats is this JSON5 text:
{ // c
a: 'x', b: 0xFF, }It loads as HOCON without any error, producing {"a":"'x'","b":"0xFF"}. JSON5.parse returns the string x and the number 255. Never rename a .json5 file to .conf. The reverse direction fails loudly: json5 2.2.3 rejects # comments, a = 1 and 30 seconds with a line and column.
Four Parsers, Same Input
We ran four implementations on November 29, 2026: com.typesafe:config 1.4.10 (Java 21), @o3co/ts.hocon 1.14.5 and @pushcorn/hocon-parser 1.3.1 (Node.js 24.22.1), and pyhocon 0.3.63 (Python 3.14.4 with pyparsing 3.3.3). The main example above, with its explicit list line, produced the same data in the Java library and both npm parsers; pyhocon agreed on the structure but returned the duration as a Python timedelta. Then we changed one line:
d { tags: [web] }
s = ${d} { name: api }
s.tags += internal| Input | Lightbend | ts.hocon | pushcorn | pyhocon |
|---|---|---|---|---|
s.tags in the sample above | ["internal"] | ["internal"] | ["web","internal"] | AttributeError |
a: http://example.com | error | "http:" | error | "http://example.com" |
a: 0x1F | "0x1F" | "0x1F" | 31 | "0x1F" |
a: 'x' | "'x'" | "'x'" | "'x'" | "'x'" |
/* c */ | error | error | error | error |
Spelling the list out as s.tags = ${d.tags} [internal] gave ["web","internal"] in all four, so prefer that form when appending to something inherited. In our environment pyhocon raised the same AttributeError even for a two-line a: [web], a += internal file, also with pyparsing 3.1.4; other version combinations may behave differently. The pushcorn package documents its own extensions, and with its strict option 0x1F stayed a string. The lesson is practical: test your real files against the exact parser that will load them in production.
Libraries by Language
Ports listed by the Lightbend README, plus the npm packages tested here. Repository and registry dates were read on November 29, 2026.
| Language | Project | Status seen |
|---|---|---|
Java | lightbend/config | 1.4.10, November 2026 |
| Scala (JVM, JS, Native) | ekrich/sconfig | Pushed November 2026 |
JavaScript / TypeScript | @o3co/ts.hocon | First published to npm in 2026; Node.js 22 or later |
| JavaScript | @pushcorn/hocon-parser | 1.3.1, June 2024 |
| JavaScript | hocon-parser (hocon-js) | 1.0.1, August 2017; README of Lightbend Config notes missing features |
Python | pyhocon | 0.3.63, March 2026 |
| gurkankaymak/hocon | Pushed November 2026 | |
C# | akkadotnet/HOCON | Pushed May 2026 |
Ruby | puppetlabs/ruby-hocon | Pushed May 2026 |
| puppetlabs/cpp-hocon | Pushed January 2025 | |
Rust | mockersf/hocon.rs | Archived; marked unmaintained by the Lightbend README, which also lists a second Rust port whose repository returned 404 when we checked |
| Erlang | emqx/hocon | Pushed October 2026; listed as an Erlang port by the Lightbend README |
A repository push is not the same as a release, and none of these dates measures conformance. For JSON5 libraries across languages, see implementations and conformance.
Where HOCON Is Used
| Project | What its documentation says |
|---|---|
| Akka | Configured through the Typesafe Config library, with application.conf and reference.conf |
| Apache Pekko | Uses the same library and layout, with settings under pekko keys; includes are used to build variants such as a development config |
| Play Framework 3.0 | The configuration file is based on Typesafe Config and uses HOCON |
| Puppet HOCON module | Listed by the Lightbend README for managing HOCON files with Puppet |
The pattern is clear: HOCON is strongest where a framework and its libraries share one configuration tree. Each JAR ships defaults in reference.conf, and the application states only its differences. If you run one of these stacks, use HOCON; fighting the framework's format gains nothing. Java developers choosing a JSON5 library for other files can start with the Java guide.
What the Power Costs
In JSON5, the value of a key is on the line where you read it. In HOCON it can be the product of several files, an include that may or may not exist, a later override, the environment, system properties and a self-reference. That is the point of the format, and also what you debug at two in the morning.
| Question | JSON5 | HOCON |
|---|---|---|
| Can the file alone tell you a value? | Yes | Not necessarily |
| Does the same file give the same data on every machine? | Yes | Depends on environment, classpath and included files |
| Can it reduce repetition? | Only in application code | Built in |
| Parser size and variation | Small grammar | Large behavior surface; implementations differ |
| Round trip to a file | stringify writes data, drops comments | Rendering writes the tree; include and substitution intent is gone after resolution |
The resolver is intricate enough that corner cases still surface. This contrived input made both 1.4.6 and 1.4.10 throw ConfigException$BugOrBroken, an internal-error type, rather than a result or a configuration error:
d { host: h, tags: [web] }
s = ${d} { port = 8080, port = ${?NOPE}, tags += internal }
s.url = "http://"${s.host}":"${s.port}Real configurations rarely stack that much on one object, and the library is mature and heavily used. The advice is simply to keep references shallow and to inspect the resolved result. The README suggests -Dconfig.trace=loads to log which files are loaded, and root().render() to print the tree with comments showing where values came from.
Layering JSON5 Files in Code
Most projects that want "a bit of HOCON" want two things: a local file over defaults, and an environment override. Both fit in a short function. Arrays replace rather than append, __proto__ keys are skipped, and the one environment variable is named explicitly:
const JSON5 = require('json5');
const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
function merge(base, over) {
const out = { ...base };
for (const [key, value] of Object.entries(over)) {
if (key === '__proto__') continue;
out[key] = Object.hasOwn(out, key) && isObject(out[key]) && isObject(value)
? merge(out[key], value)
: value;
}
return out;
}
const base = JSON5.parse(`{
// defaults
service: { host: 'localhost', port: 8080, tags: ['web'] },
timeoutMs: 30000, // 30 seconds
}`);
const local = JSON5.parse(`{
service: { tags: ['web', 'internal'] },
}`);
const config = merge(base, local);
if (process.env.SERVICE_PORT) {
config.service.port = Number(process.env.SERVICE_PORT);
}
console.log(JSON.stringify(config));
// {"service":{"host":"localhost","port":8080,"tags":["web","internal"]},"timeoutMs":30000}
// With SERVICE_PORT=9000 the port is the number 9000.Once you find yourself adding references, includes and a resolution order to this function, you are writing a configuration language. At that point adopt an existing one. See the Node.js guide for loading files.
Choosing Between Them
| Your situation | Lean toward | Why |
|---|---|---|
| Akka, Pekko or Play application | HOCON | The framework's native format, with layered defaults |
| Many environments sharing large blocks | HOCON on the JVM | Substitution and merging remove copy and paste |
| JavaScript or front-end tooling | JSON5 | Familiar syntax and a single reference parser |
| Files read by several languages | JSON5 or JSON | Less room for implementations to diverge |
| Input from users or another trust boundary | JSON5 or JSON, validated | No file, URL or environment access in the format |
| Program-generated output | JSON | HOCON reads it, and so does everything else |
The two can coexist. The Lightbend README suggests JSON for config written by scripts and HOCON for config maintained by hand, mixed through includes. To go from HOCON to JSON5, resolve the config in a real HOCON library, export the tree, and write that out. You will lose substitutions, includes and comments, and environment values become frozen strings, so review the output before committing it. Compare other options on the comparison hub.
Common Questions
Is HOCON a superset of JSON?
That is its design goal: valid JSON should produce the same data. The spec flags one caveat, duplicate keys, where HOCON defines merging.
Is HOCON a superset of JSON5?
No. Block comments and +1 are errors, while single quotes and hexadecimal numbers silently load as different strings in the Java library.
Is Lightbend Config still maintained?
Yes, in a deliberately narrow way. Releases continued into November 2026, and the README describes the library as feature complete.
Can I use HOCON outside the JVM?
Ports exist for several languages. Our tests show they can disagree with the Java library, so verify the features you rely on.
Does JSON5 have an include or variable syntax?
No. The specification defines neither. Some tools layer conventions on top of parsed files, but those belong to the tool, not the format.
Sources
(14)
- HOCON specification (HOCON.md)
- Lightbend Config README
- Lightbend Config release notes
- com.typesafe:config on Maven Central
- Akka configuration documentation
- Apache Pekko configuration documentation
- Play Framework configuration file documentation
- @o3co/ts.hocon on npm
- @pushcorn/hocon-parser on npm
- hocon-parser on npm
- pyhocon on PyPI
- mockersf/hocon.rs repository
- The JSON5 Data Interchange Format, 1.0.0
- json5 on npm
Last reviewed: November 29, 2026.
JavaScript
Python
TypeScript
Node.js
Rust
Java
C#
Ruby
Kotlin
Lua
Babel
Vite
webpack
ESLint
Prettier
VS Code
JetBrains