× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi All,

It's easy enough to validate data in DB2 columns to check if it's valid
JSON ( well formed I suppose I should say ) using code like:

Exec Sql
Select
Case
When t1.RqsText is JSON OBJECT then '1'
Else '0'
End
into :WellFormed
From SomeFile t1
where t1.ID = :Ctl_ID;

But if you just have the document in a Host Variable, is there an easy way
to validate it?
I'd rather stick to using the DB2 new JSON functions than start using YAJL.

I can see how I can could so something like this:

SqlStm = 'With t1 as ( Select ''' + jsonDoc + ''' as doc from
SysIbm/SysDummy1 ) '
+ 'Select Case When doc is JSON OBJECT then ''1'' Else ''0'' End '
+ 'From t1';

And then select the result of that into a Host Variable, but it seems a bad
solution and is problematical anyway because I'm wrapping the value for the
host variable in quotes so I'd need to check for embedded quotes and double
them up which means I'm messing with the incoming document.

Is there an obvious way I'm missing that you can, in an SQLRPGLE program,
check if a host variable contains well-formed JSON?

thanks in advance,
Craig

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.