Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vajahath/is-good-json
An npm package to check if the JSON is valid.
https://github.com/vajahath/is-good-json
json json-parser json-validation nodejs npm-package
Last synced: about 13 hours ago
JSON representation
An npm package to check if the JSON is valid.
- Host: GitHub
- URL: https://github.com/vajahath/is-good-json
- Owner: vajahath
- License: mit
- Created: 2016-12-26T10:20:37.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-19T02:48:16.000Z (over 5 years ago)
- Last Synced: 2024-12-19T05:52:21.873Z (about 1 month ago)
- Topics: json, json-parser, json-validation, nodejs, npm-package
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/is-good-json
- Size: 72.3 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# is-good-json
Simple package to validate JSON files.
[![npm](https://img.shields.io/npm/v/is-good-json.svg)](https://www.npmjs.com/package/is-good-json)
[![Build Status](https://travis-ci.org/vajahath/is-good-json.svg?branch=master)](https://travis-ci.org/vajahath/is-good-json)
[![Known Vulnerabilities](https://snyk.io/test/npm/is-good-json/badge.svg)](https://snyk.io/test/npm/is-good-json)
[![npm](https://img.shields.io/npm/dt/is-good-json.svg)](https://www.npmjs.com/package/is-good-json)
[![Greenkeeper badge](https://badges.greenkeeper.io/vajahath/is-good-json.svg)](https://greenkeeper.io/)![](https://raw.githubusercontent.com/vajahath/is-good-json/master/media/logo.png)
#### Usage
```javascript
isGoodJSON('{"kity": "Fluffy"}'); // returns parsed object
isGoodJSON('{"kity" "Fluffy"}'); // returns false
```## Install / Update
```shell
npm install --save is-good-json
```## Usage
### Syntax
`isGoodJSON();`
### Example
```javascript
// 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 objectisGoodJSON('{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
```javascript
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](https://github.com/vajahath/is-good-json/issues).
Enjoy.
## Change log
* v1.0.5, v1.0.6
* linting stuffs
* docs
* greenkeeper issues
* v1.0.4
* Perf improvements with [#1](https://github.com/vajahath/is-good-json/pull/1), (thanks [@demacdonald](https://github.com/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](https://mycolorpad.blogspot.in)