JSPM

  • Created
  • Published
  • Downloads 515235
  • Score
    100M100P100Q180531F
  • License MIT

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

NPM version NPM Downloads Build Status

About usage

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

  console.log(parse('{"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: 13,
        char: 12
      }
    }
  }
  */

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

MIT