feat(SW-977) check if json is valid

This commit is contained in:
Pontus Dreij
2024-12-17 14:21:48 +01:00
parent c635a8b072
commit 237147825c
2 changed files with 18 additions and 3 deletions

9
utils/isValidJson.ts Normal file
View File

@@ -0,0 +1,9 @@
export default function isValidJson(value: string | null | undefined): boolean {
if (!value || value === "undefined") return false
try {
JSON.parse(value)
return true
} catch {
return false
}
}