add tag
Bergi
## Bug report for output of JSON values from Postgres

Example query:
```sql
SELECT val, to_jsonb(val)
FROM (VALUES ('a'), ('"a"'), ('ab"cd')) examples(val)
```
Running this in dbfiddle at https://dbfiddle.uk/O9qn4Cex shows `""a""` and `"ab"cd"` for the json string values that contain a quote, where it should display `"\"a\""` and `"ab\"cd"` respectively. The backslash escaping is missing somehow.

Output from dbfiddle:
![screenshot](/image?hash=22c484abd7ee679d7e2037e953d6d1a57b3d489aa4002af7a1373518ceb529ea)

Output from pgadmin4:
![screenshot](/image?hash=10aedc5312adad9f633dd7e08f2b8e4d50604257ccf448cf573a50c390e68a09)
Top Answer
Bergi
Actually it's not just JSON, the problem appears with any backslashes in `text` columns:
```sql
SELECT backslash, length(backslash), quote, length(quote), backslash || quote AS concatenation
FROM (
  VALUES (''), ('\'), ('\\')
) a(backslash), (
  VALUES (''), ('"'), ('\"')
) b(quote);
```
Expected:
![image.png](/image?hash=6282c4a6f873c6c2e748a5a97f1a223b144d03c99c130ed13e54f31da56a5868)

Actual result:
![image.png](/image?hash=5e1c220fe0447c797b8782845032cfa504bf70312c31a6e7c264d2d031349851)

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.