Hsjon

hsjon

User interface for JSON.

hsjon is a syntax extension to JSON, not a replacement nor shall be added to the JSON spec.

It allows (multiline) comments, trailling commas, non-mandatory quotes to name a few.

Get it: npm install hsjon

Sample usage:

1
2
3
4
const Hjson = require('hjson');

const obj = Hjson.parse(hjsonText);
const text2 = Hjson.stringify(obj);

Sample hjson file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{
  # comments are treated like whitespace - they are not parsed

  hello:       Hello Human!

  // js style comment

  /*
  multiline comment
  multiline comment
  */

  # text
  text:        This is a valid string value.
  quote:       "You need quotes\tfor escapes"
  otherwise:   <div class="cool">life without escapes is bliss!</div>

  # keys
  abc-123:      no quotes for keys

  # 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

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

  # 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
  ]
}

GIF FTW!

hjson

Suggest a module

Comments