Page 1 of 1

Displaying JSON String in a Subfile using YAJL

Posted: Sat Sep 09, 2023 5:53 pm
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.

Re: Displaying JSON String in a Subfile using YAJL

Posted: Sat Sep 09, 2023 6:13 pm
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?

Re: Displaying JSON String in a Subfile using YAJL

Posted: Sat Sep 09, 2023 6:33 pm
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.

Re: Displaying JSON String in a Subfile using YAJL

Posted: Sat Sep 09, 2023 10:09 pm
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().

Re: Displaying JSON String in a Subfile using YAJL

Posted: Sat Sep 09, 2023 11:27 pm
by bbunney
Thank you Scott!