I have the table mytable with the column images, there I store strings like JSON objects.
This column contains invalid string in some records, not because the string is incorrect, but because when I try to cast it to JSON the query fails. Example:
`SELECT images::JSON->0 FROM mytable WHERE <any filter>`
If all elements of the JSON object are good that query works successfully, but if some string has " in incorrect place (to be specific, in this case in the title key) the error happens.
Good strings are like this:
[
{
"imagen": "http://www.myExample.com/asd1.png",
"amazon": "http://amazonExample.com/asd1.jpg",
"title": "A title 1."
},
{
"imagen": "http://www.myExample.com/asd2.png",
"amazon": "http://amazonExample.com/asd2.jpg",
"title": "A title 2."
},
{
"imagen": "http://www.myExample.com/asd3.png",
"amazon": "http://amazonExample.com/asd3.jpg",
"title": "A title 3."
}
]
Bad are like this:
[
{
"imagen": "http://www.myExample.com/asd1.png",
"amazon": "http://amazonExample.com/asd1.jpg",
"title": "A "title" 1."
},
{
"imagen": "http://www.myExample.com/asd2.png",
"amazon": "http://amazonExample.com/asd2.jpg",
"title": "A title 2."
},
{
"imagen": "http://www.myExample.com/asd3.png",
"amazon": "http://amazonExample.com/asd3.jpg",
"title": "A title 3."
}
]
Please put attention in the difference of title keys.
I need a regular expression to convert bad strings into good ones in PostgreSQL.