ohm-grammar-json
JSON parser written using the Ohm parsing framework.
Installation
npm install ohm-grammar-json
Usage
var json = ;
Analogous to Javascript's built in JSON.parse
:
json
The Ohm grammar and semantics objects are available:
jsongrammarjsonsemantics
Match json and return an Ohm match stucture:
jsongrammar // Returns a grammar objectjsongrammar // truejsongrammar // falsejsongrammarmessage // Error message
Testing
# Pull in submodules (nativejson-benchmark) git submodule init --update # Install dev dependencies npm install # Run tests npm test
Pretty Printer example
There is an example JSON pretty printer implemented in examples/pretty-printer.js
. The purpose of this example is to demonstrate
- Creating a new semantic operation on top of an existing grammar.
- Writing a semantic operation that depends on a context.
Example usage:
var PrettyPrinter = ; var str = PrettyPrinter; console;
Output:
Status
This package is intended as a demonstration of the Ohm parsing framework. If you want to parse or pretty print JSON in javascript, I recommend using the built in JSON.parse
and JSON.stringify
functions.
This project is intended to conform to ECMA 404 and as far as I know, it does.