apphouse
Version:
Component library for React that uses observable state management and theme-able components.
18 lines (17 loc) • 452 B
text/typescript
/**
* Validates a JSON string.
* @param {string} jsonString - The JSON string to validate.
* @returns {boolean} - Returns true if the JSON string is valid, otherwise returns false.
*/
export function validateJSON(jsonString: string) {
try {
const parsedJSON = JSON.parse(jsonString);
if (parsedJSON && typeof parsedJSON === 'object') {
return true;
} else {
return false;
}
} catch (error) {
return false;
}
}