I have a TEXT
column containing valid JSON string.
CREATE TABLE users(settings TEXT);
INSERT INTO users VALUES (\'{\"language\":\"en\",\"gender\":\
So I had an issue where the text was JSON. If you have this issue use this query instead. Where COLUMN is the column that contains the JSONB or JSON datatype and ATTRIBUTE is the attribute of the JSON that is a string, that you want converted into JSON.
The text will look like this, "{\"junk5\": 283774663, \"junk2\": 0, \"junk1\": 1218478497, \"junk3\":1923, \"junk4\": 63278342}"
SELECT CAST(TRIM(both '"' from jsonstring) as JSON)
FROM (
SELECT REPLACE(cast(COLUMN->'ATTRIBUTE' as text), '\"', '"')
as jsonString from TABLE where cast(COLUMN->'ATTRIBUTE' as text)LIKE '%\\%'
) as JSON_CONVERTING