JSON5 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.

Layered HOCON config sheets merging through pipes into one resolved tree beside a single flat JSON5 sheet

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.

Java logo

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.

FactHOCONJSON5
Defining documentHOCON.md, informalSpecification 1.0.0, March 2018
Reference implementationcom.typesafe:config (Java, no dependencies)json5 (JavaScript)
Latest release seen1.4.10, November 6, 20262.2.3, December 31, 2022
License of that libraryApache 2.0MIT
Usual file extension.conf.json5
Media type named by the specapplication/hoconNone 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.

Compare icon

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 = null

Loaded 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.

Table icon

Syntax Compared

FeatureJSON5HOCON
Comments// and /* */// and #; no block comments
Root bracesRequired for an objectOptional
Key separator::, =, +=, or nothing before {
CommasRequired; one trailing comma allowedA newline can replace them; one trailing comma ignored
Unquoted keysECMAScript identifier namesPath expressions: a.b.c nests, spaces are kept
Unquoted string valuesNoYes
Single-quoted stringsYesNo
Multiline stringsBackslash line continuation"""triple quotes""", taken literally
NumbersJSON plus hex, .5, 5., +1, Infinity, NaNJSON number forms only
Duplicate keysNames should be unique; behavior is left open, and json5 2.2.3 keeps the lastObjects merge; otherwise the last wins
References and environmentNo${path}, ${?path}
IncludesNoinclude 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.

Layers icon

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.

Link icon

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: 2 gives b the 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 += b is defined as a = ${?a} [b].
  • ${NAME[]} collects NAME_0, NAME_1 and 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=true lets variables prefixed CONFIG_FORCE_ override any key; _ becomes a dot, __ a hyphen and ___ an underscore.
Branch icon

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 by a: 1 loaded 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, .json and .conf and 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.

Clock icon

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.

FamilyBare number meansUnits
Durationmillisecondsns, us, ms, s, m, h, d and their long names such as minutes
Perioddaysd, w, m or mo (months), y and long names
Bytes, powers of 1000byteskB, MB, GB through YB and long names
Bytes, powers of 1024bytesK, k, Ki, KiB, M, m, Mi, MiB and so on

Results from 1.4.10:

ValuegetBytesValuegetDuration (ms)
10K10240500500
10kB1000010ms10
10KBerror: unit not recognized1m60000
1m10485762h7200000
1MB10000001werror: 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.

Warning icon

Inputs That Surprise

Each HOCON result is real output from com.typesafe:config 1.4.10; \n marks a line break.

InputHOCON resultWhat 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.comParse error at :: is forbidden unquoted, and // is a comment; quote URLs
a: Infinity\nb: .5\nc: +1Parse error+ is reserved
/* c */\na: 1Parse errorNo 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.

Test icon

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
InputLightbendts.hoconpushcornpyhocon
s.tags in the sample above["internal"]["internal"]["web","internal"]AttributeError
a: http://example.comerror"http:"error"http://example.com"
a: 0x1F"0x1F""0x1F"31"0x1F"
a: 'x'"'x'""'x'""'x'""'x'"
/* c */errorerrorerrorerror

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.

Library icon

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.

LanguageProjectStatus seen
Java logoJavalightbend/config1.4.10, November 2026
Scala (JVM, JS, Native)ekrich/sconfigPushed November 2026
JavaScript logoJavaScript / TypeScript@o3co/ts.hoconFirst published to npm in 2026; Node.js 22 or later
JavaScript@pushcorn/hocon-parser1.3.1, June 2024
JavaScripthocon-parser (hocon-js)1.0.1, August 2017; README of Lightbend Config notes missing features
Python logoPythonpyhocon0.3.63, March 2026
Go logoGogurkankaymak/hoconPushed November 2026
C# logoC#akkadotnet/HOCONPushed May 2026
Ruby logoRubypuppetlabs/ruby-hoconPushed May 2026
C++ logoC++puppetlabs/cpp-hoconPushed January 2025
Rust logoRustmockersf/hocon.rsArchived; marked unmaintained by the Lightbend README, which also lists a second Rust port whose repository returned 404 when we checked
Erlangemqx/hoconPushed 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.

Server icon

Where HOCON Is Used

ProjectWhat its documentation says
AkkaConfigured through the Typesafe Config library, with application.conf and reference.conf
Apache PekkoUses the same library and layout, with settings under pekko keys; includes are used to build variants such as a development config
Play Framework 3.0The configuration file is based on Typesafe Config and uses HOCON
Puppet HOCON moduleListed 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.

Structure icon

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.

QuestionJSON5HOCON
Can the file alone tell you a value?YesNot necessarily
Does the same file give the same data on every machine?YesDepends on environment, classpath and included files
Can it reduce repetition?Only in application codeBuilt in
Parser size and variationSmall grammarLarge behavior surface; implementations differ
Round trip to a filestringify writes data, drops commentsRendering 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.

JavaScript logo

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.

Checklist icon

Choosing Between Them

Your situationLean towardWhy
Akka, Pekko or Play applicationHOCONThe framework's native format, with layered defaults
Many environments sharing large blocksHOCON on the JVMSubstitution and merging remove copy and paste
JavaScript or front-end toolingJSON5Familiar syntax and a single reference parser
Files read by several languagesJSON5 or JSONLess room for implementations to diverge
Input from users or another trust boundaryJSON5 or JSON, validatedNo file, URL or environment access in the format
Program-generated outputJSONHOCON 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.

Question icon

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.