is-json-object
v1.0.2
Published
Fast test to determine if an object is JSON-like
Downloads
1
Readme
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
andInfinitiy
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