@azizbecha/strkit
Version:
strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.
21 lines • 513 B
JavaScript
/**
* Checks if a string is a valid JSON format.
*
* @param str - The string to check.
* @returns A boolean indicating whether the string is valid JSON.
*
* @example
* isJSON('{"name": "John", "age": 30}'); // Output: true
* isJSON('{name: John, age: 30}'); // Output: false
* isJSON('random string'); // Output: false
*/
export default function isJSON(str) {
try {
JSON.parse(str);
return true;
}
catch (_a) {
return false;
}
}
//# sourceMappingURL=isJSON.js.map