node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »



JSON-san, you much parse error!

json-san is a json module that works pretty much like the built-in JSON object EXCEPT:

  • On json.parse errors, json-san uses jshint to provide useful error messages on how to fix it!
  • json-san knows how to rock callbacks!


npm install json-san


Here's an example of the more useful error messages:

> require("./lib/json-san").parse("[ 'foo' ]")

      * line 1, col 4, Strings must use doublequote.

1 error

    at Object.parse (/home/josh/jsonhint/lib/json-san.js:22:13)
    at [object Context]:1:27
    at Interface.<anonymous> (repl.js:171:22)
    at Interface.emit (events.js:64:17)
    at Interface._onLine (readline.js:153:10)
    at Interface._line (readline.js:408:8)
    at Interface._ttyWrite (readline.js:585:14)
    at ReadStream.<anonymous> (readline.js:73:12)
    at ReadStream.emit (events.js:81:20)
    at ReadStream._emitKey (tty_posix.js:307:10)

See? Now you know where the mistake is!

Now here's an example of using a callback with stringify (which of course doesn't have jshint integration):

> require("./lib/json-san").stringify(["foo"], function (err, json) {
...   if (err) {
...     throw err;
...   } else {
...     console.log(json);
...   }
... });


npm test

Developers! Developers! Developers!

If you like what you see (or don't quite like what you see), I heartily invite you to dig in, fork it up and git push it good.