1

Please find the below jsonb object where i need to replace all apostrophe from instruction key.

    [{
        "instruction": "Don't need to book car for M'lore location",
        "reservationNo": "TT00098272"
    },
    {
        "instruction": "Please book a car for mumbai location",
        "reservationNo": "TT00098273"
    }
 ]

Expected Result : values are replace with apostrophe

[{
            "instruction": "Dont need to book car for Mlore location",
            "reservationNo": "TT00098272"
        },
        {
            "instruction": "Please book a car for mumbai location",
            "reservationNo": "TT00098273"
        }
     ]
1
  • Just check with replace(jsoncolumn::text,'''','')::json Commented Dec 24, 2019 at 8:56

1 Answer 1

1

You can do a regexp_replace() after casting to text:

postgres=# create table j (field jsonb);
CREATE TABLE
postgres=# insert into j values ('[{
postgres'#         "instruction": "Don''t need to book car for M''lore location",
postgres'#         "reservationNo": "TT00098272"
postgres'#     },
postgres'#     {
postgres'#         "instruction": "Please book a car for mumbai location",
postgres'#         "reservationNo": "TT00098273"
postgres'#     }
postgres'#  ]'::jsonb);
INSERT 0 1
postgres=# select regexp_replace(field::text,'''','','g')::jsonb from j;
                                                                                    regexp_replace                                                                                     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 [{"instruction": "Dont need to book car for Mlore location", "reservationNo": "TT00098272"}, {"instruction": "Please book a car for mumbai location", "reservationNo": "TT00098273"}]
(1 row)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.