Re: IS JSON STRICT - In oracle => postgres ??

From: Holger Jakobs <holger(at)jakobs(dot)com>
To: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: IS JSON STRICT - In oracle => postgres ??
Date: 2023-06-14 14:09:14
Message-ID: 776384e5-2480-e950-9390-3212f3033856@jakobs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Am 14.06.23 um 12:00 schrieb Nikhil Ingale:
> Hi All,
> In oracle we can use the *is json* check constraint for the json
> column to ensure the data is well formed.
>
> How do we ensure the same in postgres database?
>
> Regards,
> Nikhil Ingale

Hi Nikhil,

If you insist that you want to check without putting the content into a
JSON(B) column, you might try this function:

|create or replace function is_valid_json(p_json text) returns boolean
as $$ begin return (p_json::json is not null); exception when others
then return false; end; $$ language plpgsql immutable;|

https://stackoverflow.com/questions/30187554/how-to-verify-a-string-is-valid-json-in-postgresql

It just tries to cast the text to JSON. If it can be casted, it's valid
JSON, otherwise it's not.

Regards,

Holger

--
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message M Sarwar 2023-06-14 14:51:24 Re: How to use long list of columns with COPY command
Previous Message hubert depesz lubaczewski 2023-06-14 10:19:01 Re: How to read wal files in postgresql 15?