0.0.5 • Published 12 months ago

tiny-json5-parser v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

tiny-json5-parser

codecov

A parser for json5.

Installation and Usage

Node.js

npm install tiny-json5-parser

CommonJS

const JSON5 = require('tiny-json5-parser');

const content = `
{
  // comments
  unquoted: 'and you can quote me on that',
  singleQuotes: 'I can use "double quotes" here',
  lineBreaks: "Look, Mom! \
No \\n's!",
  hexadecimal: 0xdecaf,
  leadingDecimalPoint: .8675309, andTrailing: 8675309.,
  positiveSign: +1,
  trailingComma: 'in objects', andIn: ['arrays',],
  "backwardsCompatible": "with JSON",
}
`;
const result = JSON5.parse(content);
console.log(result);
// {
//     unquoted: 'and you can quote me on that',
//         singleQuotes: 'I can use "double quotes" here',
//     lineBreaks: "Look, Mom! No \n's!",
//     hexadecimal: 912559,
//     leadingDecimalPoint: 0.8675309,
//     andTrailing: 8675309,
//     positiveSign: 1,
//     trailingComma: 'in objects',
//     andIn: [ 'arrays' ],
//     backwardsCompatible: 'with JSON'
// }

Modules

import * as JSON5 from 'tiny-json5-parser';

const content = `
{
  // comments
  unquoted: 'and you can quote me on that',
  singleQuotes: 'I can use "double quotes" here',
  lineBreaks: "Look, Mom! \
No \\n's!",
  hexadecimal: 0xdecaf,
  leadingDecimalPoint: .8675309, andTrailing: 8675309.,
  positiveSign: +1,
  trailingComma: 'in objects', andIn: ['arrays',],
  "backwardsCompatible": "with JSON",
}
`;
const result = JSON5.parse(content);
console.log(result);
// {
//     unquoted: 'and you can quote me on that',
//         singleQuotes: 'I can use "double quotes" here',
//     lineBreaks: "Look, Mom! No \n's!",
//     hexadecimal: 912559,
//     leadingDecimalPoint: 0.8675309,
//     andTrailing: 8675309,
//     positiveSign: 1,
//     trailingComma: 'in objects',
//     andIn: [ 'arrays' ],
//     backwardsCompatible: 'with JSON'
// }
0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago