On this page
Scalar literal matrix#
SELECT 'null'::json, 'true'::json, '123'::json, '-123.456'::json, '1e10'::json, '"hello"'::json;
SELECT 'null'::jsonb, '1e-100'::jsonb, '-1e100'::jsonb;
SELECT jsonb_typeof('[]'::jsonb), jsonb_typeof('{}'::jsonb); -- array | objectNegative array indexes#
SELECT '[10,20,30]'::jsonb -> 0; -- 10
SELECT '[10,20,30]'::jsonb -> -1; -- 30 (from the end)
SELECT '[10,20,30]'::jsonb ->> -1; -- '30'
SELECT '[10,20,30]'::jsonb #> '{-1}';
SELECT '{"a":{"b":[{"c":42}]}}'::jsonb #>> '{a,b,0,c}'; -- '42'Escape matrix#
SELECT '"quote: \"hello\""'::jsonb, '"slash: \/"'::jsonb, '"tab: \t"'::jsonb;
SELECT E'"unicode: \\u0041"'::jsonb; -- "A", incl. surrogate pairs \uD83D\uDE00Numeric extremes#
SELECT '1.0000000000000000000000001'::jsonb, '1e100'::jsonb;
SELECT '999999999999999999999999999999999999999999'::jsonb;Invalid JSON — catch it with DO/EXCEPTION#
DO $$
BEGIN
PERFORM '"bad: \q"'::jsonb;
EXCEPTION WHEN OTHERS THEN
RAISE NOTICE 'EXPECTED INVALID ESCAPE: %', SQLERRM;
END $$;Invalid escapes, short \u12 sequences, and malformed numbers raise — never silently coerce. Wrap ingestion casts in DO … EXCEPTION or validate with IS JSON first:
SELECT payload FROM events WHERE payload IS JSON; Was this page helpful? Thanks — noted locally, nothing is sent anywhere.