roles-bot/packages/bot/utils/isJson.ts
2022-04-10 21:09:37 +02:00

11 lines
No EOL
274 B
TypeScript

export const isJSON = (data: any): boolean => {
if (typeof data !== 'string') return false;
try {
const result = JSON.parse(data);
const type = result.toString();
return type === '[object Object]' || type === '[object Array]';
} catch (err) {
return false;
}
};