es-toolkit/docs/reference/predicate/isJSONObject.md
knott ded56755f3
Some checks failed
CI / codecov (push) Has been cancelled
Release / release (push) Has been cancelled
feat(isJSONObject, isJSONValue, isJSONArray): Implement isJSONObject, isJSONValue, isJSONArray (#563)
* feat:init

* feat

* fix:use prettier

* feat(isPlainObject): Update signature of isPlainObject

* feat: Add isJSONValue, isJSONArray, and refactor isJSONObject

* remove from functions

* docs: Update docs

* docs: Update docs

* docs: Update docs

* docs: Update docs

* docs: Update docs

* docs: Update docs

* docs: Update docs

---------

Co-authored-by: Sojin Park <raon0211@gmail.com>
Co-authored-by: Sojin Park <raon0211@toss.im>
2024-09-29 20:42:50 +09:00

705 B

isJSONObject

Checks if a value is a JSON object.

A valid JSON object is defined as an object with string keys and valid JSON values.

Signature

function isJSONObject(obj: unknown): obj is Record<string, any>;

Parameters

  • value (unknown): The value to check.

Returns

(obj is Record<string, any>): True if the value is a JSON object, otherwise false.

Examples

console.log(isJSONObject({ nested: { boolean: true, array: [1, 2, 3], string: 'test', number: 1, null: null } })); // true
console.log(isJSONObject({})); // true
console.log(isJSONObject({ regexp: /test/ })); // false
console.log(isJSONObject(123)); // false