Hi All,
I've written quite a lot of code using the DB2 JSON functions and it works
pretty well.
I've been using JSON_TABLE in lax mode and checking null indicators for any
mandatory keys.
But I've been concerned that with this approach, any misspelled optional
keys just get lost.
So I've started trying to use strict mode.
But unless I am missing something, I think that strict mode insists on all
specified keys to be present in the object.
Does anyone know if there is a way of using JSON_TABLE() such that absent
keys are just treated as null but misspelled keys are reported as errors?
For example:
I would like:
Select t1.ItemRef,
t1.ManuDate,
t1.AltRef,
t1.Grade
From WsInq00 t2,
JSON_TABLE(
t2.RqsText,
'strict $'
ERROR ON ERROR
COLUMNS(
ItemRef CHAR( 20 ) PATH 'strict $.itemRef',
ManuDate CHAR( 10 ) PATH 'strict $.manuDate'
AltRef CHAR( 30 ) PATH 'strict $.altRef',
Grade CHAR( 3 ) PATH 'strict $.grade'
)
) as t1
Where t2.UniqueID = 100982;
to accept this:
{
"itemRef": "SRSWLVB5GZWYS33LP9MQ",
"grade": "8EY"
}
because all *present *fields are correct keys
but reject this:
{
"itemRef": "SRSWLVB5GZWYS33LP9MQ",
"Grade": "8EY"
}
Because the Grade key is spelled with a capitol G and it should not be.
Is there a way of achieving this?
Thanks kindly,
Craig
As an Amazon Associate we earn from qualifying purchases.