Search code examples
postgresqlregexp-replace

Postgresql regexp_replace() backslash and double quotes


I am trying to import JSON file where a value contains data like this

"\"Koslov Git †girish\" Ges"

The return should be like "Koslov Git †girish Ges"

The extra \" are the troubles

I tried REGEXP_REPLACE(values, '\\''+', '''', 'g') with no luck. How can I get rid of this. Note the first and last double quotes should not be replaced


Solution

  • with data(json_object) as (
        values ('"\"Koslov Git †girish\" Ges"'::jsonb)
    )
    
    select regexp_replace(json_object::text, '\\"', '', 'g')
    from data;
    

    Db<>fiddle.