Feedback on GitHub

Hjson is JSON - commas + comments for Humans

JSON is a data-interchange format for machines. Hjson tries to be close to its syntax, so you don't have to learn anything new, but to make it more readable and easier to edit.

Use it

In Hjson, you can

That means that you can write:

{
  # look, no quotes or commas!
  foo: Hello World!
  bar: Hello Hjson!

  # don't bother with escapes
  html: <div class="hello">world</div>

  # Hjson is a superset so the normal JSON syntax can be used
  "array": [ 1, "two" ]
}

instead of:

{
  "foo": "Hello World!",
  "bar": "Hello Hjson!",
  "html": "<div class=\"hello\">world</div>",
  "array": [ 1, "two" ]
}

Implementations

Why?

# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
#
#LogLevel: warn
#LogLevel: debug
LogLevel: notice
{
  "foo": "Hello World!",
  "bar": "Hello Hjson!"
  "bar2": "Hello Again!"
}

Why not ...

FAQ:

Sample:

{
  # comments are treated like whitespace - they are not parsed

  # text
  text:        This is a valid string value.
  quote:       "You need quotes\tfor escapes"
  otherwise:   a \ is just a \

  # multiline text
  multiline:
    '''
    first line
      indented line
    third line
    '''

  # keys
  abc123:      no quotes for keys that contain only a-z, A-Z and 0-9
  "a/b.c ":    a key with any other characters still needs quotes

  # comma
  commas:      "can be omitted at the end of the line"
  but:         [ 1, 2, 3 ] # not between elements on the same line
  trailing:    [ 1, 2, 3, ] # a trailing comma is OK

  # numbers, keywords and arrays work just like in JSON
  number:      5
  negative:    -4.2
  yes:         true
  no:          false
  null:        null
  array:       [ 1, 2 ]
  array2:      [
    1
    2
  ]
}

is equivalent to the following JSON:

{
  "text":      "This is a valid string value.",
  "quote":     "You need quotes\tfor escapes",
  "otherwise": "a \\ is just a \\",
  "multiline": "first line\n  indented line\nthird line\n",
  "abc123":    "no quotes for keys that contain only a-z, A-Z and 0-9",
  "a/b.c ":    "a key with any other characters still needs quotes",
  "commas":    "can be omitted at the end of the line",
  "but":       [ 1, 2, 3 ],
  "trailing":  [ 1, 2, 3 ],
  "number":    5,
  "negative":  -4.2,
  "yes":       true,
  "no":        false,
  "null":      null,
  "array":     [ 1, 2 ],
  "array2":    [
    1,
    2
  ]
}