isJSONValue(value: unknown): value is
Checks if a given value is a valid JSON value.
A valid JSON value can be:
- null
- a JSON object (an object with string keys and valid JSON values)
- a JSON array (an array of valid JSON values)
- a string
- a number
- a boolean
Example 1
Example 1
console.log(isJSONValue(null)); // true console.log(isJSONValue({ key: "value" })); // true console.log(isJSONValue([1, 2, 3])); // true console.log(isJSONValue("Hello")); // true console.log(isJSONValue(42)); // true console.log(isJSONValue(true)); // true console.log(isJSONValue(undefined)); // false console.log(isJSONValue(() => {})); // false