Relaxed JSON

Are you frustrated that you cannot add comments into your configuration JSON Relaxed JSON is a simple solution. expand ↓

Relaxed JSON is a small JavaScript library with only two exposed function RJSON.transform(text : string) : string and RJSON.parse(text : string, reviver : function | opts : object).

Relaxed JSON (modified BSD license) is a strict superset of JSON, relaxing strictness of valilla JSON. Valid, vanilla JSON will not be changed by RJSON.transform. But there are few additional features helping writing JSON by hand.

Check out the source and additional documentation on GitHub.

↑ collapse

Example

/* This is a test input
 * Comments are omitted
 */
{
  numbers: [
    0, -0, 1, -1,
    23.45, -23.45,
    1e2, -1e2, 1.3e4, -1.3e4,
    1.5e+6, -1.5e+6, 77.88e-99, -77.88e-99,
  ],
  object: {
    foo: bar, // identifiers are transformed into strings
    plus-operation: +, // and even some lispy identifiers
    saw: /\/\/\/\/\/\,
    'quux': null, // and single quoted strings are allowed
    t: /* boolean */ true,
    f: false,
    say: 'Hello, "World"',
    escaping1: "Foo \"bar'",
    escaping2: 'Foo "bar\'',
    escaping3: "Foo\nbar in \"quux\"",
  }, // trailing comma
}
 
 
                       
                       
   
{
  "numbers": [
    0, -0, 1, -1,
    23.45, -23.45,
    1e2, -1e2, 1.3e4, -1.3e4,
    1.5e+6, -1.5e+6, 77.88e-99, -77.88e-99 
  ],
  "object": {
    "foo": "bar",                                            
    "plus-operation": "+",                                   
    "saw": "/\\/\\/\\/\\/\\/\\",
    "quux": null,                                         
    "t":               true,
    "f": false,
    "say": "Hello, \"World\"",
    "escaping1": "Foo \"bar'",
    "escaping2": "Foo \"bar'",
    "escaping3": "Foo\nbar in \"quux\"" 
  }                   
}
 
 

This is a JSON linter!

Relaxed JSON, by Oleg Grenrus

Fork me on GitHub