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 })
isJSON(new Foo)
isJSON('test test test')
License
The MIT License