Notorious Penguin Magicians
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

is-good-json

1.0.6 • Public • Published

is-good-json

Simple package to validate JSON files.

npm Build Status Known Vulnerabilities npm Greenkeeper badge

Usage

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

Install / Update

npm install --save is-good-json

Usage

Syntax

isGoodJSON(<argument>);

Example

// 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

Usage

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.


Enjoy.

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

License

MIT © Vajahath Ahmed

install

npm i is-good-json

Downloadsweekly downloads

14

version

1.0.6

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar