1.0.2 • Published 6 years ago

is-json-object v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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