mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-07 09:51:37 +00:00
harden json normalization in postgres migration script
This commit is contained in:
parent
c0a4ce1396
commit
8593721c35
1 changed files with 14 additions and 2 deletions
|
|
@ -89,10 +89,22 @@ function normalizeBoolean(value) {
|
|||
function normalizeJson(value) {
|
||||
if (value === null || value === undefined || value === '') return null
|
||||
if (typeof value === 'object') return value
|
||||
|
||||
const textValue = String(value)
|
||||
|
||||
try {
|
||||
return JSON.parse(value)
|
||||
const parsed = JSON.parse(textValue)
|
||||
if (typeof parsed === 'string') {
|
||||
try {
|
||||
return JSON.parse(parsed)
|
||||
} catch (error) {
|
||||
return parsed
|
||||
}
|
||||
}
|
||||
return parsed
|
||||
} catch (error) {
|
||||
return value
|
||||
// Keep non-JSON payloads as JSON string values so inserts remain valid.
|
||||
return JSON.stringify(textValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue