From: | Greig Wise <greigwise(at)comcast(dot)net> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | JSON fields with backslashes |
Date: | 2023-10-13 21:51:31 |
Message-ID: | FBF57852-29F3-4688-86F9-DEFF678A6139@comcast.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello. I have run into an issue when using the copy command on tables with json columns where Postgres seems to improperly escape backslashes under certain conditions thus creating invalid JSON. Here is an example I have of the behavior:
create table test_json(json_data json);
insert into test_json values ('{"test1": "2011-01-01", "description":"test\ntest2\ntest3 test''s\n \"Quoted Phrase\" test\ntest."}’);
copy test_json to '/var/tmp/t.json’;
cat /var/tmp/t.json
{"test1": "2011-01-01", "description":"test\\ntest2\\ntest3 test's\\n \\"Quoted Phrase\\" test\\ntest."}
Note that the quotes within the json field have \\ in front, thus negating the escape of the quotes around “Quoted Phrase”. Which then renders the whole thing invalid JSON. Is this a bug?
I am using PostgreSQL V12.16.
Thanks,
Greig Wise
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2023-10-13 22:01:02 | Re: JSON fields with backslashes |
Previous Message | Pavel Luzanov | 2023-10-13 20:54:20 | Re: psql \du no more showing "member of" column |