From: Romain MAZIÈRE <romain.maziere@sigmaz-consilium.fr>
To: Andreas Joseph Krogh <andreas@visena.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Delete values from JSON
Date: Fri, 17 Mar 2023 11:56:22 +0100
Message-ID: <f75f4e31-e9e0-d765-503a-f0da42e87d57@sigmaz-consilium.fr> (raw)
In-Reply-To: <VisenaEmail.bc7.d4292f85844d033f.186ee909d72@origo01.app.internal.visena.net>
References: <VisenaEmail.bc7.d4292f85844d033f.186ee909d72@origo01.app.internal.visena.net>
Hi,
If it is jsonb type, you can have a look at the documentation :
https://www.postgresql.org/docs/14/functions-json.html
There are some examples :
|jsonb| |-| |text| → |jsonb|
Deletes a key (and its value) from a JSON object, or matching string
value(s) from a JSON array.
|'{"a": "b", "c": "d"}'::jsonb - 'a'| → |{"c": "d"}|
|'["a", "b", "c", "b"]'::jsonb - 'b'| → |["a", "c"]|
|jsonb| |-| |text[]| → |jsonb|
Deletes all matching keys or array elements from the left operand.
|'{"a": "b", "c": "d"}'::jsonb - '{a,c}'::text[]| → |{}|
|jsonb| |-| |integer| → |jsonb|
Deletes the array element with specified index (negative integers count
from the end). Throws an error if JSON value is not an array.
|'["a", "b"]'::jsonb - 1| → |["a"]|
|jsonb| |#-| |text[]| → |jsonb|
Deletes the field or array element at the specified path, where path
elements can be either field keys or array indexes.
|'["a", {"b":1}]'::jsonb #- '{1,b}'| → |["a", {}]|
Regards
Romain MAZIÈRE
romain.maziere@sigmaz-consilium.fr
+33.535.545.085
+33.781.46.36.96
https://sigmaz-consilium.fr
Le 17/03/2023 à 08:56, Andreas Joseph Krogh a écrit :
>
> Hi, in PG-14, how do I delete the keys |"dunsNumber": "NaN"|:
>
> |{ "sessionId": "ce6fc9d0-5923-4d71-9f7e-ae60f35c45d6", "details": [ {
> "keyInformation": { "dunsNumber": "NaN", "organizationType":
> "LIMITED_COMPANY" } }, { "keyInformation": { "dunsNumber": "123",
> "organizationType": "LIMITED_COMPANY" } } ], "nisse": 123 }|
>
> So that the result becomes:
>
> |{ "sessionId": "ce6fc9d0-5923-4d71-9f7e-ae60f35c45d6", "details": [ {
> "keyInformation": { "organizationType": "LIMITED_COMPANY" } }, {
> "keyInformation": { "dunsNumber": "123", "organizationType":
> "LIMITED_COMPANY" } } ], "nisse": 123 }|
>
> Thanks.
>
> --
> *Andreas Joseph Krogh*
> CTO / Partner - Visena AS
> Mobile: +47 909 56 963
> andreas@visena.com
> www.visena.com <https://www.visena.com;
> <https://www.visena.com;
Attachments:pTf753EUtNRv0MU6.png (image/png, 1.9K) downloadview image
OpenPGP_0x97C05C89DEC4129F.asc (application/pgp-keys, 3.1K) download
OpenPGP_signature (application/pgp-signature, 839B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: romain.maziere@sigmaz-consilium.fr, andreas@visena.com
Subject: Re: Delete values from JSON
In-Reply-To: <f75f4e31-e9e0-d765-503a-f0da42e87d57@sigmaz-consilium.fr>
References: <VisenaEmail.bc7.d4292f85844d033f.186ee909d72@origo01.app.internal.visena.net> <f75f4e31-e9e0-d765-503a-f0da42e87d57@sigmaz-consilium.fr>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox