Introduction HOCON is a setting or configuration file format used during software development for storing configuration related data. HOCON is abbreviated as Human-Optimized Configuration Object Notation

It is a modern format that serves as superset of JSON, which means any JSON file can be used as a hocon configuration file. It is designed to be more human friendly while maintains power, elegent, flexible need for complex configuration files.

What is HOCON?

HOCON used to store configuration files similar to toml or ini . It is designeed by combined best features of JSON with additional features that makes more suitable for configuration management.

This course series posts help you to get the basics of HOCON with examples for learning. Key features:

  • Readability: Hocon format is more readable than other configuraiton format such as TOML, YAML. THe Syntax is similar to JSON with strict free validation rules, making easier to write and maintain..

  • Nested Structure: It supports parent and child relationships in a hierarchial tree format. It allows to organizae configuration data in a logical nested structure that’s easy to understand and manage.

    database {
    host = "localhost"
    port = 5432
    credentials {
      username = "admin"
      password = "password"
      }
    }
    
  • Easy syntax It is case sensitive and uses file extension .conf, Unllike some other forats, Tabs are not allowed, but spaces are supported in most of the editors.

For example, The below three configuration entries are equalvalent in the Hocon Configuration file

 { "key"=value } or
 "key"=value,  or
  key=value  or

Advantages

  • Lightweight
  • It is very easy and simple to represent the complex mapping
  • Friendly readable and writable
  • Simple to modify with any text editor
  • Suitable for configuration settings
  • Merging
  • substitution
  • Complex configuration can be declared.

Disadvantages

  • It is a new format introduced recently, and a learning curve exists.
  • Not much popular other than XML and json

hocon file extension

hocon files created with the extension .conf or .hocon You can use any IDE or text editor to open and create this file.

All the popular IDE supports the hocon file extension and also provide plugins to validate the hocon file content.

MIME format type - application/hocon

There is no office MIME type for hocon document content as per IANA , but it can be represented using application/hocon

When hocon data is transferred between client and server, Implementation vendors add MIME type settings specified in request and response across the internet. Content-Type and accept headers in a request object are specified with this format following is the mime type for this document

application/hocon

and request contains the below value for hocon data sending over the internet

Content-type : application/hocon:

Features

  • Strict JSON syntax
  • Comments
  • Variable substitution
  • Map and array values
  • Includes other hocon configuration files

Hocon Syntax Reference

  • parenthesis ({}) to Root element is ignored
  • You can use key and value with a separator (: or =)
  • Double quotes to keys and values are not required and optional
  • Objects or array attributes are separated by a new line
  • Comments always start with # or \