@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.
24 lines • 601 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = isJSON;
/**
* 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
*/
function isJSON(str) {
try {
JSON.parse(str);
return true;
}
catch (_a) {
return false;
}
}
//# sourceMappingURL=isJSON.js.map