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

Dependencies (1)

Dev Dependencies (3)

Package Sidebar

Install

npm i is-json-object

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • samvv