Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ppb6S-000765-S5 for pgsql-general@arkaria.postgresql.org; Thu, 20 Apr 2023 20:42:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ppb6R-00074a-8m for pgsql-general@arkaria.postgresql.org; Thu, 20 Apr 2023 20:42:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ppb6Q-00074R-UL for pgsql-general@lists.postgresql.org; Thu, 20 Apr 2023 20:42:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ppb6O-000wGS-LV for pgsql-general@lists.postgresql.org; Thu, 20 Apr 2023 20:42:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 33KKfudV3176186; Thu, 20 Apr 2023 16:41:56 -0400 From: Tom Lane To: Marc Millas cc: Erik Wienhold , "pgsql-general@lists.postgresql.org" Subject: Re: missing something about json syntax In-reply-to: References: <422485092.653228.1682012851663@office.mailbox.org> Comments: In-reply-to Marc Millas message dated "Thu, 20 Apr 2023 21:53:29 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3176184.1682023316.1@sss.pgh.pa.us> Date: Thu, 20 Apr 2023 16:41:56 -0400 Message-ID: <3176185.1682023316@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Marc Millas writes: > but it doesnt explain how postgres is able to put a scalar in a json or > jsonb column without pb: > I don't understand how this ('"{\"t\"}"') can be considered a valid enough > json to be inserted in a json column > and at the same time invalid for all other json uses. That's a bare string (it's not an object). That's valid JSON per RFC 7159: JSON can represent four primitive types (strings, numbers, booleans, and null) and two structured types (objects and arrays). ... A JSON text is a serialized value. Note that certain previous specifications of JSON constrained a JSON text to be an object or an array. However, there certainly are some operations that require the top-level value to be an object or array. regards, tom lane