1
This commit is contained in:
18
server/services/json_utils.js
Normal file
18
server/services/json_utils.js
Normal file
@@ -0,0 +1,18 @@
|
||||
export function safe_json_stringify(value) {
|
||||
try {
|
||||
return JSON.stringify(value);
|
||||
} catch (err) {
|
||||
return JSON.stringify({ error: 'json_stringify_failed', message: String(err) });
|
||||
}
|
||||
}
|
||||
|
||||
export function safe_json_parse(text) {
|
||||
if (text === null || text === undefined || text === '') {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user