roles-bot/src/bot/isJson.ts

11 lines
309 B
TypeScript
Raw Normal View History

2021-12-21 12:55:10 +01:00
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;
}
}