Skip to content

Commit 765105c

Browse files
committed
feat: add validateJSON validator
1 parent 96f740b commit 765105c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Shared/validations.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,17 @@ export const validateUniqueKeys = (keys: string[]) => {
248248
message: `Duplicate variable name: ${duplicateKeys.join(', ')}`,
249249
}
250250
}
251+
252+
export const validateJSON = (json: string): ValidationResponseType => {
253+
try {
254+
JSON.parse(json)
255+
return {
256+
isValid: true,
257+
}
258+
} catch (err) {
259+
return {
260+
isValid: false,
261+
message: err.message,
262+
}
263+
}
264+
}

0 commit comments

Comments
 (0)