Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

smikhalevski/json-ast-visitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON AST Visitor

JSON abstract syntax tree parser, visitor and serializer.

import {parseJson, traverseJsonAst, generateJson, JsonVisitor, NumberNode} from 'json-ast-visitor';

const json = [{foo: 'bar'}];
const jsonAst = parseJson(json);

class FooVisitor extends JsonVisitor {

  visitString(node) {
    if (node.getKey() === 'foo') {
      node.replace(new NumberNode(123));
    }
  }
}

traverseJsonAst(jsonAst, new FooVisitor())
  .then(generateJson)
  .then(json => console.log(json)) // → [{foo: 123}]

Scripts

npm run flow Run Flow type checks.

npm test Run Jest test suite.

npm run build Build project into target/out directory.

About

JSON abstract syntax tree parser and serializer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published