Hjson Syntax

TL;DR here

Object

{memberLF,member,}

Member

JSON-stringany character except ,:[]{} and whitespace:value

Array

[valueLF,value,]

Value

stringnumberobjectarraytruefalsenull

String

JSON-StringQuoteless-StringMultiline-String

JSON-String

"any character except " or \\\reverse solidus"quotation mark/solidusbbackspacefformfeednnewlinercarriage returnthorizontal tabu4 hexadecimal digits"

Quoteless-String

any character except ,:[]{}any character except LF

Multiline-String

'''any character except three ' in a row'''

Number

-0digit 1-9digit.digiteE+-digit

Comments

#any character except LF//any character except LF/*anything but * followed by /*/

Character means any UNICODE character except the control characters.

Details

Commas

You can separate your values/members either with a comma or a new line.

Unlike JSON, trailing commas are ignored and do not produce a syntax error.

For example:

{
  one: 1
  two: 2,
  more: [3,4,5]
  trailing: 6,
}

You should omit optional commas to make your data more readable.

{
  one: 1
  two: 2
}

Whitespace & Comments

Whitespace and comments can be inserted between any pair of tokens.

Hash # or C style // comments start a single line comment.

The style is just a matter of preference. # may be easier on the eyes but // is sometimes used in existing JSON configs.

/* starts a multiline comment that ends with */. You can use it to comment out part of the data.

Keys

You only need to add quotes if the key name includes whitespace or any of the punctuators ({}[],:).

For example:

Quoteless Strings

A quoteless string cannot start with any of the punctuators ({}[],:).

Unlike a quoted string it automatically ends at the end of the current line. Do not add commas or comments as they would become part of the string. If you wish to add comments place them on the previous or next line.

Preceding and trailing whitespace is ignored. Escapes are only supported in quoted strings.

The Hjson parser will still detect values (number, true, false or null) and parse them correctly. For example

Multiline Strings

A multiline string is OS and file independent. The line feed is always \n.

For example

haiku:
  '''
  My half empty glass,
  I will fill your empty half.
  Now you are half full.
  '''

Is the string "My half empty glass,\nI will fill your empty half.\nNow you are half full."

Root Braces - OBSOLETE

While Hjson allows you to omit {} for the root object, this feature should no longer be used.

File extension

.hjson

Encoding

.hjson files must be encoded in UTF-8 (without a BOM).

Hjson does not have a header but if you want to indicate the file type you can use #hjson on the first line.

RFC

View the RFC draft (pending updates)

Users Developers Syntax Try FAQ Feedback History