Files
omni-tools/src/pages/tools/json/validateJson/service.ts
Ibrahima G. Coulibaly 8461270024 refactor: validateJson
2025-03-09 15:49:44 +00:00

14 lines
336 B
TypeScript

export const validateJson = (
input: string
): { valid: boolean; error?: string } => {
try {
JSON.parse(input);
return { valid: true };
} catch (error) {
if (error instanceof SyntaxError) {
return { valid: false, error: error.message };
}
return { valid: false, error: 'Unknown error occurred' };
}
};