Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vxRGT-00E78H-1x for pgsql-bugs@arkaria.postgresql.org; Tue, 03 Mar 2026 15:02:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vxRGR-007PG5-33 for pgsql-bugs@arkaria.postgresql.org; Tue, 03 Mar 2026 15:02:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vxRGR-007PFw-2F for pgsql-bugs@lists.postgresql.org; Tue, 03 Mar 2026 15:02:24 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vxRGQ-00000000C3t-20Eq for pgsql-bugs@lists.postgresql.org; Tue, 03 Mar 2026 15:02:23 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-65c01595082so8900158a12.3 for ; Tue, 03 Mar 2026 07:02:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772550141; x=1773154941; darn=lists.postgresql.org; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:from:to:cc:subject:date:message-id:reply-to; bh=anVUXBgbTdbhfyiPzrRx9YTVPLJLstt4UNk/EBEE37M=; b=Tx9Bi6kvrHggu9L3qjNuf3Rinvf8S4gsca17OezYjkQjzHrBDN0NbtK0fdRUd6TOka NNbJzAI7nTJ8y+0rxswsbemYgO5IQUc9qksUixr3XFNmjmxsytjSODEuJIXQkIM6F61o DH7lTLL7V0gNwINNTDTW1rSdZ7O1zMMhQY9MO/Rhb+xBwSq0KMEu9nIPHdPI39SIbOiM SLAQ06OopLl3l4gMFGsWV8LJEe2aHMY1oNUmD1g/taM+IZr+561Lw0NpZMRXZfy/CtEl zcWYe/Q1NVf5Zm3EiwpqtURglOfG59f1srBv+bUQjkABpIQ8Y0UT1q2ey6kXOUrEMUCJ n/Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772550141; x=1773154941; h=to:date:message-id:subject:mime-version:content-transfer-encoding :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=anVUXBgbTdbhfyiPzrRx9YTVPLJLstt4UNk/EBEE37M=; b=jcWbLkiV8iMLa7SfcMSzJy3qadEUbkoFqKIqTf4xAqJHFX7nKIL7CC8K5Su7tbDrhQ 6SUQ8fu854PXAuhgjFJt6p/S7gh14yjXrcBovXKIG0BQASedtgmDDYpjPRAIIFvLUvQm HeekFC4d8uqZZs9ovHqDyQ6e7qBox2RSs2ZYs/xSnPG0X7XnDT2nhSPTkrxjummzUcO6 L77H8GFgc6HukXzJLNtwvC+TzrrXRIEbHyXcSb2Y7hBpQWiNu+Luy8bCgsIa42dBCYEJ cFyt2NwUM5xZCR3bnR7Czb2pC4bdM5jJx7WLFHkOgPmBZCSeRZXCeSxs7guHwfUOKf1i h2oQ== X-Gm-Message-State: AOJu0YxqyrCkX9SZ1BRv/NBuVLp6xwp6bpUlMDzZ2gNcLIXTA1dEG907 pDabp0vAb+MU2wqtksZuPI1k/CI5iFqiN01neTTRXPwIWYAsWvf2GhyXO3FxCA== X-Gm-Gg: ATEYQzwD4tkkw900S9kTa7MaW2P75++PdMm0DB6zDFLZdX0pcwTl2583sUNNLAgmXT3 dEjtpBpeuVGxuO/6Sc7u5I7yhEzVTmR50EqISbn+VGWB5iYGtFzHFh9ehnTPhJMZ6vwxwCyQ7U7 zp8OKIJC9fP+0xPcpgIOjzP+DhV8+2t2C0QtPuovFBXlwh5BhVcsJJYNN11Ho5j9Ip+ZY0ES8J/ CXw6OJNztw6ySbdBQpq0AvRNNtyN0A4J/Vp2Tdo1qxtl5ve4Z6K0wS9n5ex6GXIh9ErCI9qrvSt u/nGecg1qhnSKSJq0j4hi+CQWAxFwqGhpjHKXyuLcVbnQRXBkpbXJ+nK7cj5nA6bptCWNXaupiN d1kHhpu7oQHp23VRsSp6eN81/UUf1TRP9/2jNyLnVjxyOzP12lbo2p5KOGgCggwE4T+9mYbXLGv A1stc1CyhjgR6fRsNOVwrMZX3mvFAv/G/dK7NFTDnOAIiHmO5rAE1mV+kvnPvHqoWaA61X3I3J7 xc9R3qyBvKJT8HMc8ReJMRrl+4foRoFkoHJs7Y= X-Received: by 2002:a17:907:3d50:b0:b8f:a8bc:a081 with SMTP id a640c23a62f3a-b9376385cccmr1063785266b.19.1772550140252; Tue, 03 Mar 2026 07:02:20 -0800 (PST) Received: from smtpclient.apple (2a02-a445-9da0-0-20eb-af92-c7ea-5de0.fixed6.kpn.net. [2a02:a445:9da0:0:20eb:af92:c7ea:5de0]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b935ac704b0sm602042366b.22.2026.03.03.07.02.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Mar 2026 07:02:18 -0800 (PST) From: Dirkjan Bussink Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: JSON_SERIALIZE for JSONB returns parts of the internal JSONB representation Message-Id: <03583FE7-A5EE-407C-907D-67865F3F8BFC@gmail.com> Date: Tue, 3 Mar 2026 16:02:08 +0100 To: pgsql-bugs@lists.postgresql.org X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, When running a query like this (tested against PostgreSQL 18.3), it = shows internals from the JSONB storage: postgres=3D# select JSON_SERIALIZE('[1,2,4]'::jsonb); json_serialize ---------------- \x03 (1 row) I think this qualifies as a bug? I would expect JSON_SERIALIZE to either = work with JSONB and here output the serialized text, so '[1,2,4]', or to = error that JSONB is not supported for this function (or that this = function can=E2=80=99t even be found for a JSONB argument).=20 What happens here is that json_out treats the internal bytes from the = JSONB representation as a C string.=20 =46rom src/include/utils/jsonb.h: * ... For that purpose, both an array and an object begin with a uint32 * header field, which contains an JB_FOBJECT or JB_FARRAY flag. This is part of the header: typedef struct JsonbContainer { uint32 header; /* number of elements or key/value pairs, and * flags */ JEntry children[FLEXIBLE_ARRAY_MEMBER]; /* the data for each child node follows. */ } JsonbContainer; The rest of the header contains the number of elements, in this case a = JSON array of 3 elements. So the total header looks like=20 uint32(JB_FARRAY | 3) =3D=3D 0x40000003 So this also explains the \x03 output above. What is seen there is the = first byte of the header there as little endian, since that is = interpreted as a C string with the a 0 byte that happens to be after = there.=20 --=20 Cheers, Dirkjan=