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
Install
> npm install json-to-ast
Usage
var parse = require('json-to-ast');
var settings = {
verbose: true, // Show additional information, like node’s location. Default is <true>
source: 'data.json' // Adds filename information to node’s location. Default is <null>
};
parse('{"a": 1}', settings);
Output
{
type: 'object',
children: [
{
type: 'property',
key: {
type: 'identifier',
value: 'a',
loc: {
start: { line: 1, column: 2, offset: 1 },
end: { line: 1, column: 5, offset: 4 },
source: 'data.json'
}
},
value: {
type: 'literal',
value: 1,
rawValue: '1',
loc: {
start: { line: 1, column: 7, offset: 6 },
end: { line: 1, column: 8, offset: 7 },
source: 'data.json'
}
},
loc: {
start: { line: 1, column: 2, offset: 1 },
end: { line: 1, column: 8, offset: 7 },
source: 'data.json'
}
}
],
loc: {
start: { line: 1, column: 1, offset: 0 },
end: { line: 1, column: 9, offset: 8 },
source: 'data.json'
}
}
Node types
object:
{
type: 'object',
children: <property[]>,
loc: {...}
}
property:
{
type: 'property',
key: <identifier>,
value: <literal | object | array>,
loc: {...}
}
identifier:
{
type: 'identifier',
value: <String>,
loc: {...}
}
array:
{
type: 'array',
children: <value[]>,
loc: {...}
}
literal:
{
type: 'literal',
value: <String | Number | Boolean | null>,
rawValue: <String>,
loc: {...}
}
License
MIT