isJSONValue
Import from @varavel/vdl-plugin-sdk/utils/predicates.
function isJSONValue(value): value is string | number | boolean | any[] | Record<string, any> | null;
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
Parameters
| Parameter | Type | Description |
|---|---|---|
value |
unknown |
The value to check. |
Returns
value is string | number | boolean | any[] | Record\<string, any> | null
- True if the value is a valid JSON value, otherwise false.
Example
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