JSON AST parser

Install
> npm install json-to-ast
Usage
const parse = require('json-to-ast');
const settings = {
// Appends location information. Default is <true>
loc: true,
// Appends source information to node’s location. Default is <null>
source: 'data.json'
};
parse('{"a": 1}', settings);
Output
{
type: 'Object',
children: [
{
type: 'Property',
key: {
type: 'Identifier',
value: 'a',
raw: '"a"',
loc: {
start: { line: 1, column: 2, offset: 1 },
end: { line: 1, column: 5, offset: 4 },
source: 'data.json'
}
},
value: {
type: 'Literal',
value: 1,
raw: '1',
Node types
Object:
{
type: 'Object',
children: <Property[]>,
loc?: Object
}
Property:
{
type: 'Property',
key: <Identifier>,
value: <Object | Array | Literal>,
loc?: Object
}
Identifier:
{
type: 'Identifier',
value: String,
raw: String,
loc?: Object
}
Array:
{
type: 'Array',
children: <(Object | Array | Literal)[]>,
loc?: Object
}
Literal:
{
type: 'Literal',
value: String | Number | Boolean | null,
raw: String,
loc?: Object
}
AST explorer
Try it online on astexplorer.net
License
MIT