Great Json
The greatjson module is a JSON.parse replacement providing clearer syntax messages with line and column numbers, expected tokens and offending text. In addition, errors are returned instead of thrown.
Get It Now
- GreatJson is on github
Usage
Example of parsing with greatjson:
var greatjson = var result error // example how to use successfullyif !result = greatjson instanceof Error // It works! I got: 17 console // example of parse failureif !error = greatjson instanceof Error ;else // SyntaxError: Unexpected token: expected json value, text:'qwerty' at line:1 column:1 position: 0 (0%) console // example of missing commaif !error = greatjson instanceof Error ;else // SyntaxError: Bad token: expected object comma, text:'"b":6.' at line:1 column:7 position: 6 (50%) console // printout of custom error properties var s = for var p in error s // Error properties: position:6 line:1 column:7 text:"b":6. console
Notes
(c) Harald Rudell wrote this for the love of node in August, 2012
Great Json is based on work by
JavaScript Object Notation or json is a language-independent text format.
rfc4627: the application/json media type.
JSON.parse in secion 15.12.2 of JavaScript.
No warranty expressed or implied. Use at your own risk.
Please suggest better ways, new features, and possible difficulties on github