JSPM

  • Created
  • Published
  • Downloads 515235
  • Score
    100M100P100Q180512F
  • 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

npm install json-to-ast

API

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
    }
  }
}
*/

AST format

Object:

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

Array:

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

Primitive:

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

Try out online (Fork of astexplorer.net)

License

MIT