An npm package to check if the JSON is valid and not empty

Usage no npm install needed!

<script type="module">
  import isGoodJson from '';



Simple package to validate JSON files.

npm Build Status Known Vulnerabilities npm Greenkeeper badge


isGoodJSON('{"kity": "Fluffy"}'); // returns parsed object
isGoodJSON('{"kity" "Fluffy"}'); // returns false

Install / Update

npm install --save is-good-json





// load package
const isGoodJSON = require('is-good-json');

// use it
isGoodJSON('{"this": "is","a": "good json"}'); // -> returns parsed object: {"this": "is","a": "good json"}
isGoodJSON({ this: 'is', a: 'good json' }); // -> returns same object

isGoodJSON('{ha: "hi" meuo: "ho"}'); // -> returns false
isGoodJSON('[{"ths":asdf}{"adasd":asdf}]'); // -> returns false

// empty arrays and objects
isGoodJSON('[]'); // -> returns false
isGoodJSON('{}'); // -> returns false
isGoodJSON([]); // -> returns false
isGoodJSON({}); // -> returns false


Syntax : b = isGoodJSON(a);

where a and b are as follows,

value of a value of b
null false
true or false false
any number false
valid json as string parsed json object
valid json as object same json object
invalid json as string false
invalid json as object false
valid, but empty json false
valid non-empty object same object
valid non-empty array same array
valid, but empty object false
valid, but empty array false

one more example

isGoodJSON('{"name": "Kitty", "friends":["tom", "jerry"]}');
/* returns the following parsed object:
        name: "kitty",
        friends: ["tom", "jerry"]

If you wish to file any feature/bugs, mention it on issues.


Change log

  • v1.0.5, v1.0.6
    • linting stuffs
    • docs
    • greenkeeper issues
  • v1.0.4
    • Perf improvements with #1, (thanks @demacdonald)
    • adds Greenkeeper, tavis ci.
  • v1.0.3
    • Documentation updates.
  • v1.0.2
    • Dependency adjustments.
  • v1.0.1
    • Github integration done right.
  • v1.0.0
    • Initial release


MIT © Vajahath Ahmed