npm

npm’s 2019 JavaScript ecosystem survey analysis is now available! Get your copy here »

is-json-object

1.0.2 • Public • Published

This is a small package with a minimal footprint that tries to detect if an object is a JSON-like value in the most generic way possible, using the following rules for edge cases

  • Though not specified in the standard, root objects may be other values than plain objects
  • NaN and Infinitiy are not acceptable JSON values, as per the standard
  • Objects constructed with Object.create(null) will be accepted
  • Array-like objects with a length property will get accepted

These rules should cover most common use cases, while users requiring more fine-grained contol can take a look at the source (it isn't that much).

Usage

const isJSON = require('is-json-object')
 
class Foo {  }
 
isJSON({ a: 1, b: 2 }) // true
isJSON(new Foo) // false
isJSON('test test test') // true

License

The MIT License

install

npm i is-json-object

Downloadsweekly downloads

3

version

1.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability