1.0.4 • Published 6 years ago

json-ast-visitor v1.0.4

Weekly downloads
13
License
-
Repository
github
Last release
6 years ago

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.

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago