Displaying JSON String in a Subfile using YAJL

Discussions relating to the ScottKlement.com port of the open source YAJL JSON Reader/Generator. This includes the YAJL tool as well as the YAJLR4, YAJLGEN, YAJLINTO and YAJLDTAGEN add-ons from ScottKlement.com. http://www.scottklement.com/yajl/
Post Reply
bbunney
Posts: 45
Joined: Wed Jul 06, 2022 7:52 pm

Displaying JSON String in a Subfile using YAJL

Post by bbunney »

I want to take nested data structures with data in them, create a formatted JSON string and then write the JSON string into a subfile for viewing. I went through the Working with JSON and RPG PDF. We use YAJL in our web services. After you do the last YAJL_ENDOBJ() is the data in a string somewhere and if it is how does YAJL know what string to place it in? If it's not in a string, how can I get it into a string that I can parse and load a subfile with? Thanks.
jonboy49
Posts: 206
Joined: Wed Jul 28, 2021 8:18 pm

Re: Displaying JSON String in a Subfile using YAJL

Post by jonboy49 »

If you have a nested data structure as the source of your JSON why not just use DATA-GEN with YAJLGEN rather than the YAQJL routines directly?
bbunney
Posts: 45
Joined: Wed Jul 06, 2022 7:52 pm

Re: Displaying JSON String in a Subfile using YAJL

Post by bbunney »

I believe that DATA-GEN didn't come out until IBM i 7.3+ and we have to compile at IBM i 7.2 until all of our LPAR's have been converted to IBM i 7.4. So I will still like to know where the JSON data is placed once the last YAJL_ENDOBJ() is run so I can access it. Thanks.
Scott Klement
Site Admin
Posts: 658
Joined: Sun Jul 04, 2021 5:12 am

Re: Displaying JSON String in a Subfile using YAJL

Post by Scott Klement »

Call yajl_copyBufStr() to copy the JSON data from YAJL into a string in your program.

Code: Select all

myVariable = yajl_copyBufStr();
If you need to handle more than 2mb, use yajl_copyBuf() instead. This does require working with pointers, so I would avoid it unless you can't use yajl_copyBufStr().
bbunney
Posts: 45
Joined: Wed Jul 06, 2022 7:52 pm

Re: Displaying JSON String in a Subfile using YAJL

Post by bbunney »

Thank you Scott!
Post Reply