json-to-ast

WebJar for json-to-ast

License

License

MIT
Categories

Categories

JSON Data
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

json-to-ast
Last Version

Last Version

2.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

json-to-ast
WebJar for json-to-ast
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/vtrushin/json-to-ast

Download json-to-ast

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/json-to-ast/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>json-to-ast</artifactId>
    <version>2.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/json-to-ast/
implementation 'org.webjars.npm:json-to-ast:2.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/json-to-ast/
implementation ("org.webjars.npm:json-to-ast:2.1.0")
'org.webjars.npm:json-to-ast:jar:2.1.0'
<dependency org="org.webjars.npm" name="json-to-ast" rev="2.1.0">
  <artifact name="json-to-ast" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='json-to-ast', version='2.1.0')
)
libraryDependencies += "org.webjars.npm" % "json-to-ast" % "2.1.0"
[org.webjars.npm/json-to-ast "2.1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : code-error-fragment jar [0.0.230]
org.webjars.npm : grapheme-splitter jar [1.0.4,2)

Project Modules

There are no modules declared in this project.

JSON AST parser

NPM NPM downloads Requirements Travis-CI

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',
        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?: 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

Versions

Version
2.1.0
2.0.0-alpha1.3