UNPKG

diginext-utils

Version:
28 lines (27 loc) 601 B
/** * Check if the object or string is in JSON format */ export const isValid = (content) => { if (typeof content == "object") { try { content = JSON.stringify(content); } catch (err) { return false; } } if (typeof content == "string") { try { content = JSON.parse(content); } catch (err) { return false; } } if (typeof content != "object") { return false; } return true; }; const xjson = { isValid }; export default xjson;