hocon
is a super set of JSON file type, So JSON syntax almost works in hocon configuration file.
So Every syntax of JSON objects works with hocon configuration.
Hocon configuration Syntax
Configuration can be defined with key
and value
.
Here is an simple configuration defined in hocon .conf file
Here is an syntax
key:value
key=value
key is an string value
value can be string, boolean ,array or map or number
key and value are separated by colon(:
) or equal (=
) symbol
The same syntax can be declared and rewritten as follows
{
key:value
key=value
}
Root element braces({}
) are omitted
The below configuration is also valid
key:value
The same can be rewritten in JSON
{
"key":"value"
}
Let’s see some examples of different key and values
String value example in hocon
{
keystring:"keyvalue"
keystring1:"keyvalue1"
}
Number value example in hocon
{
keyinteger:12
keyfloat:11.0
}
boolean value example
{
keyboolean:true
keyboolean1:false
keyboolean2:yes
keyboolean3:no
}
Array values example
Array contain group of values enclosed in square brackets []
.
The values in array can be strings, booleans, integers
emptyArray: []
intArray: [11, 12, 13]
stringArray: ["one","two","three"]
booleanArray: [true,false,yes,no]
Object can also be declared as values in hocon configuration
dev: {
hostname: dev.site.com,
username: username,
password: password,
}
Comments
Comments are useful text to describe about each line of text. This will be ignored by processor or compiler during reading.
It supports inline comments and these always stats with ‘//’ and ‘#’
// this is inline comment
\# this is another inline comment
Includes
This is one of the important feature which is not availiable in JSON. This is used to include multiple files
let’s declare database.conf which contain common properties database.conf
database.port=5712
database.ssenabled=true
dev.conf
include "database.conf"
hostname: dev.site.com,
username: username,
password: password,
Substitution variable
Hocon supports Substitution variable using ${}
syntax
It replaces the variable with variable as seen below
devprofile {
hostname: dev
}
devpath: ${devprofile.hostname}:8080