If it is a valid JSON-String, you may use JSON Value to get the Data:
Example:
Values(JSON_Value('{"Id": 1000,
"Name": {"FirstName": "Anna",
"LastName": "Meier"},
"Phone": [{"CountryCode": "0049",
"AreaCode": "08191",
"PhoneNumber": "239806"},
{"CountryCode": "0049",
"AreaCode": "06023",
"PhoneNumber": "33445"}],
"Status": "Okay"}' Format JSON,
'$.Status'));

If you copy and paste and run the example you should get Okay returned

Mit freundlichen Grüßen / Best regards

Birgitta Hauser
Modernization – Education – Consulting on IBM i
Database and Software Architect
IBM Champion since 2020

"Shoot for the moon, even if you miss, you'll land among the stars." (Les Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them and keeping them!"
"Train people well enough so they can leave, treat them well enough so they don't want to. " (Richard Branson)
"Learning is experience … everything else is only information!" (Albert Einstein)


-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Daniel Gross
Sent: Tuesday, 3 February 2026 16:13
To: midrange-l@xxxxxxxxxxxxxxxxxx
Subject: Re: sql to scan and substring

If the JSON is incomplete / not parsable, the simplest and at the same time most complicated way to solve that might be REGEXP_SUBSTR und building a regular expression to find exactly what you need.

-> https://www.ibm.com/docs/en/i/7.6.0?topic=functions-regexp-substr

Take some of the JSON strings paste them at

-> https://regex101.com/

Then build a regular expression which hits your status strings as you want them.

The regex

"status":"(.+)"

should find the "status" part and wraps the contents of its value into a capture group. And

regexp_substr(
your_json, '"status":"(.+)"', 1, 1, '', 1
)

should do the extraction of the first occurrence in that JSON string.

If you need more help, send a little bit more of your JSON and what you want exactly to find or extract, and I can try to figure out something.

HTH
Daniel



Am 03.02.2026 um 15:30 schrieb Vern Hamberg via MIDRANGE-L <midrange-l@xxxxxxxxxxxxxxxxxx>:

Hi Jim

I sometimes use the POSSTR function to get where a string is, along with adding to the returned value to get the end or start of the next thing.

Now if values and all are broken apart and on different rows, maybe you could put them back together with LISTAGG. That function does need something on each row to identify what should go together.

*Regards*

*Vern Hamberg*

IBM Champion 2025 <cid:part1.U4VznBDg.CfM1fKGm@centurylink.net> CAAC
(COMMON Americas Advisory Council) IBM Influencer 2023


On 2/3/2026 8:11 AM, Jim Franz wrote:
I'm trying to select the value from a log file which holds part of
large json rows, but the json incomplete and not readable so the
"status" never in same position. I need the value of status.or even
the whole string "status":"Paid"
(scan and substring may be wrong description) sample data
"status":"Paid","allow ],"status":"Declined",

I can picture this in RPGLE but trying to improve my sql...
Found solutions online but not DB2.

Jim Franz
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx To
subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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

This mailing list archive is Copyright 1997-2026 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.