refactor: validateJson

This commit is contained in:
Ibrahima G. Coulibaly
2025-03-09 15:49:44 +00:00
parent d7587d526a
commit 8461270024
3 changed files with 53 additions and 67 deletions

View File

@@ -0,0 +1,13 @@
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' };
}
};