Reconsider using JSON for configuration #5933

Open
opened 2026-01-31 00:25:49 +00:00 by claunia · 0 comments
Owner

Originally created by @flying-sheep on GitHub (Jan 15, 2020).

Originally assigned to: @DHowett on GitHub.

Description of the new feature/enhancement

Having tried out quite a few editors and IDEs as well as programming languages and their infrastructure, I’m pretty sure I can argue from experience:

JSON, while being a decent serialization language, is a bad configuration language.

It has a few traits that make it nice to write parsers for, but unnecessarily restrictive for manual editing as configuration:

  • No comments. This is such a pain that many extend it to have this.
  • No trailing commas. That simply makes it annoying to add list or dict entries at the end, and makes VCS diffs unnecessarily noisy.
  • Mandatory quotes. Config keys are often chosen to be valid identifiers, so allowing a subset of many languages’ identifiers ([A-Za-z_][A-Za-z0-9_]*) to work as dict keys without quotes would remove a lot of visual noise.
  • No multiline strings. Sometimes you want one of these (e.g. for a long regex or a template) without having to squeeze it all into one line with \ns.
  • Lack of visual structure. There’s only dicts and arrays, while config files often benefit from being split into sections (I.e. a nicer syntax for the top level dict)
  • No NaN or Inf. That comes straight from its JavaScript heritage and has no justification outside of it.

JSON isn’t designed to be a config language and it shows. (Actually I googled “json as configuration” and found this article which happens to be a long form of what I just typed)

Proposed technical implementation details (optional)

If your configuration is (or can be made) flat enough that TOML works, I’d recommend it. It’s basically a more sane, standardized version of INI. It fixes all of the above and more. After all, it’s designed to be a config language!

If you really need deep nesting (I assume almost nobody does and they just didn’t try finding a schema that’s flatter), CSON or a YAML subset would work, but there’s nothing that’s both simple and widely used.

Originally created by @flying-sheep on GitHub (Jan 15, 2020). Originally assigned to: @DHowett on GitHub. # Description of the new feature/enhancement Having tried out quite a few editors and IDEs as well as programming languages and their infrastructure, I’m pretty sure I can argue from experience: JSON, while being a decent serialization language, is a bad configuration language. It has a few traits that make it nice to write parsers for, but unnecessarily restrictive for manual editing as configuration: - No comments. This is such a pain that many extend it to have this. - No trailing commas. That simply makes it annoying to add list or dict entries at the end, and makes VCS diffs unnecessarily noisy. - Mandatory quotes. Config keys are often chosen to be valid identifiers, so allowing a subset of many languages’ identifiers (`[A-Za-z_][A-Za-z0-9_]*`) to work as dict keys without quotes would remove a lot of visual noise. - No multiline strings. Sometimes you want one of these (e.g. for a long regex or a template) without having to squeeze it all into one line with `\n`s. - Lack of visual structure. There’s only dicts and arrays, while config files often benefit from being split into sections (I.e. a nicer syntax for the top level dict) - No `NaN` or `Inf`. That comes straight from its JavaScript heritage and has no justification outside of it. JSON isn’t designed to be a config language and it shows. (Actually I googled “json as configuration” and found [this article](https://www.lucidchart.com/techblog/2018/07/16/why-json-isnt-a-good-configuration-language/) which happens to be a long form of what I just typed) # Proposed technical implementation details (optional) If your configuration is (or can be made) flat enough that TOML works, I’d recommend it. It’s basically a more sane, standardized version of INI. It fixes all of the above and more. After all, it’s designed to be a config language! If you *really* need deep nesting (I assume almost nobody does and they just didn’t try finding a schema that’s flatter), CSON or a YAML subset would work, but there’s nothing that’s both simple and widely used.
claunia added the Issue-QuestionNeeds-Tag-FixResolution-Answered labels 2026-01-31 00:25:49 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#5933