Skip to content

ahmedash95/js-json-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON parser

JSON parser built in JS that can

  • Build an AST for JSON
  • Parse json text to JS object

NOTE: Its not for production

Install

npm i js-nasty-json-parser

Usage

AST - to parse JSON and get an AST

const { Parser } = require('js-nasty-json-parser/parser');

const p = new Parser(`{"name": "Json Parser"}`)

console.log(p.parse())

/** output **/
{
  "type": "Object",
  "body": [
    {
      "type": "PropertyExpression",
      "key": {
        "type": "StringLiteral",
        "value": "name"
      },
      "value": {
        "type": "StringLiteral",
        "value": "Json Parser"
      }
    }
  ]
}

Object - to parse json string and get JS object

const { JsonBuilder } = require('js-nasty-json-parser/builder');

const b = new JsonBuilder()

console.log(b.build(`{"name": "Json Parser"}`));

/** output **/
{ 
  name: 'Json Parser' 
}

Testing

If you don't have JEST. you can run

yarn install

and to run tests

jest --verbose

About

JSON parser implemented in JS (JUST FOR FUN)

Resources

Stars

Watchers

Forks

Packages

No packages published