CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
isJSON.d.mts32 linesDownload Raw Back to predicate
1/**2 * Checks if a given value is a valid JSON string.3 *4 * A valid JSON string is one that can be successfully parsed using `JSON.parse()`. According to JSON5 * specifications, valid JSON can represent:6 * - Objects (with string keys and valid JSON values)7 * - Arrays (containing valid JSON values)8 * - Strings9 * - Numbers10 * - Booleans11 * - null12 *13 * String values like `"null"`, `"true"`, `"false"`, and numeric strings (e.g., `"42"`) are considered14 * valid JSON and will return true.15 *16 * This function serves as a type guard in TypeScript, narrowing the type of the argument to `string`.17 *18 * @param {unknown} value The value to check.19 * @returns {boolean} Returns `true` if `value` is a valid JSON string, else `false`.20 *21 * @example22 * isJSON('{"name":"John","age":30}'); // true23 * isJSON('[1,2,3]'); // true24 * isJSON('true'); // true25 * isJSON('invalid json'); // false26 * isJSON({ name: 'John' }); // false (not a string)27 * isJSON(null); // false (not a string)28 */29declare function isJSON(value: unknown): value is string;30 31export { isJSON };32 
basant307/AI_Governance_Project · CoolFace