JSON validation behavior - Mailing list pgsql-hackers

From Sergei Kornilov
Subject JSON validation behavior
Date
Msg-id 6996811540391041@sas1-890ba5c2334a.qloud-c.yandex.net
Whole thread Raw
Responses Re: JSON validation behavior  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-hackers
Hi

We have some json regression tests in src/test/regress/expected/json_encoding_1.out with \u0000 symbol

select json '{ "a":  "null \u0000 escape" }' as not_unescaped;
         not_unescaped          
--------------------------------
 { "a":  "null \u0000 escape" }
(1 row)

select json '{ "a":  "null \u0000 escape" }' ->> 'a' as fails;
ERROR:  unsupported Unicode escape sequence
DETAIL:  \u0000 cannot be converted to text.
CONTEXT:  JSON data, line 1: { "a":...

Well, requested text type can not have \u0000 byte. But seems strange: we test json type with this value but raise same
errorfor -> operator:
 

melkij=> select json '{ "a": "null \u0000 escape"}' -> 'a' as fails;
ERROR:  unsupported Unicode escape sequence
DETAIL:  \u0000 cannot be converted to text.
CONTEXT:  JSON data, line 1: { "a":...

Result was requested in json datatype, like 'SELECT '"\u0000"'::json;' from tests before.
Similar error with access by different key:

melkij=> select json '{ "a": "null \u0000 escape", "b":1 }' ->>'b' as fails;
ERROR:  unsupported Unicode escape sequence
DETAIL:  \u0000 cannot be converted to text.
CONTEXT:  JSON data, line 1: { "a":...

We allow write such json to table, we allow read whole json, but we can not use native operators. Is this behavior
expected?

regards, Sergei


pgsql-hackers by date:

Previous
From: David Fetter
Date:
Subject: Re: Log timestamps at higher resolution
Next
From: Tom Lane
Date:
Subject: Re: Estimating number of distinct values.