Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yosuke-furukawa/json5x

JSON5 for JSX
https://github.com/yosuke-furukawa/json5x

Last synced: about 1 month ago
JSON representation

JSON5 for JSX

Awesome Lists containing this project

README

        

JSON5 library for JSX
========================

[JSON5](http://json5.org/) is really useful library for json.
JSON5 can add comments and last commas are available.

Getting Started
===============

```shell
$ npm install json5x -S
```

usage:

```js
import "json5/json5.jsx";

class _Test extends TestCase {
function testParse() : void {
var testData = """
{
foo: 'bar',
while: true,

this: 'is a \
multi-line string',

// this is an inline comment
here: 'is another', // inline comment

/* this is a block comment
that continues on another line */

hex: 0xDEADbeef,
half: .5,
delta: +10,
to: Infinity, // and beyond!

finally: 'a trailing comma',
oh: [
"we shouldn't forget",
'arrays can have',
'trailing commas too',
],
}
""";
var testJson = JSON5.parse(testData);
this.expect(testJson["foo"]).toBe("bar");
this.expect(testJson["while"]).toBe(true);
this.expect(testJson["this"]).toMatch(/^is a .*/);
this.expect(testJson["this"]).toMatch(/.* multi-line string/);
this.expect(testJson["here"]).toBe("is another");
this.expect(testJson["hex"]).toBe(0xDEADbeef);
this.expect(testJson["half"]).toBe(0.5);
this.expect(testJson["delta"]).toBe(10);
this.expect(testJson["to"]).toBe(Infinity);
this.expect(testJson["finally"]).toBe("a trailing comma");
this.expect(testJson["oh"]).toEqual([ "we shouldn't forget", "arrays can have", "trailing commas too"]);
}
```

LICENSE
=========

MIT