From: Pavel Stehule <pavel.stehule@gmail.com>
To: Michael Moore <michaeljmoore@gmail.com>
Cc: postgres list <pgsql-sql@postgresql.org>
Subject: Re: remove null values from json
Date: Tue, 19 Jan 2016 19:09:06 +0100
Message-ID: <CAFj8pRCHZmLKiYpGmdbFYeeqK8PQ9u0acQ6W4vU9TshO2J=4wQ@mail.gmail.com> (raw)
In-Reply-To: <CACpWLjMXYaOJ+qDGX4xAduhWTHt0F62K2e2sDazH7tG_m9Qnpg@mail.gmail.com>
References: <CACpWLjMXYaOJ+qDGX4xAduhWTHt0F62K2e2sDazH7tG_m9Qnpg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>
2016-01-15 21:24 GMT+01:00 Michael Moore <michaeljmoore@gmail.com>:
> This is ALMOST what I want:
> select json_strip_nulls ('[{ "f1":1 , "f2":null , "f3":"NULL" , "f4":""
> }]');
> the result is:
> "[{"f1":1,"f3":"NULL","f4":""}]"
>
> As you can see, the "f2" object has been removed. I would *also* like to
> remove the f3 and f4 objects.
>
> I realize I won't be able to use the json_strip_nulls function to do this.
> I could brute force it by doing "json to array" then looping through the
> array and picking only the objects I want, and then using the chosen
> objects to build an new JSON document.
>
> I suspect there is a more elegant way to accomplish the same objective.
> Ideas?
>
if you generate JSON from zero, then replace "" and "NULL" by NULL before
jsonification.
Pavel
>
> PS. It would be great to have a json_strip_values (json, array) where
> array contains the list of values you want removed.
>
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: pavel.stehule@gmail.com, michaeljmoore@gmail.com
Subject: Re: remove null values from json
In-Reply-To: <CAFj8pRCHZmLKiYpGmdbFYeeqK8PQ9u0acQ6W4vU9TshO2J=4wQ@mail.gmail.com>
* 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