JSPM

  • Created
  • Published
  • Downloads 515235
  • Score
    100M100P100Q180423F
  • License ISC

JSON parser with AST output

Package Exports

  • json-to-ast

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-to-ast) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

JSON AST parser

Usage

  var Parser = require('json-to-ast');

  console.log(new Parser('{"a": 1}'))
  /*
  =>
  {
    type: 'object',
    properties: [
      {
        type: 'property',
        key: {
          type: 'key',
          value: 'a',
          position: {
            start: {
              line: 1,
              column: 2,
              char: 1
            },
            end: {
              line: 1,
              column: 9,
              char: 8
            }
          }
        },
        value: {
          type: 'number',
          value: '1',
          position: {
            start: {
              line: 1,
              column: 11,
              char: 10
            },
            end: {
              line: 1,
              column: 12,
              char: 11
            }
          }
        }
      }
    ],
    position: {
      start: {
        line: 1,
        column: 1,
        char: 0,
      },
      end: {
        line: 1,
        column: 15,
        char: 14
      }
    }
  }
  */

Output

AST format for object

{
  type: 'object',
  properties: [
    {
      type: 'property',
      key: {
        type: 'key',
        value: 'keyName',
        position: {
            start: {
                line: ...,
                column: ...,
                char: ...
            },
            end: {
                line: ...,
                column: ...,
                char: ...
            }
        }
      },
      value: ...
    }
  ],
  position: {...}
}

for array

{
  type: 'array',
  items: [
    ...
  ],
  position: {...}
}

for primitive type

{
  type: 'string|number|true|false|null',
  value: ...,
  position: {...}
}

Try out in online (Look at console)

License

ICS