Page 1 of 1

parse error: premature EOF

Posted: Thu Jun 09, 2022 11:23 am
by gio.cot
we have a json variable with length more than 65535 (this json variable is the response of a web service !) ; when we try to run "docNode = yajl_buf_load_tree(%addr(json:*data) :%len(%trimr(json)):errMsg ); " in the docNode we find *NULL . The problem is the variable length ? how we can solve this problem ?
Thanks in advance
Gio

Json Example
P.S. is not important to import the encoded data
{
"order_nbr": "XXXXX-",
"delivery_booked": true,
"items": [
{
"item_number": "1",
"my_ord_id": "1074",
"tracking_url": "xxxxx"
}
],
"waybills": [
{
"from_code": "307",
"encoded": "JVBERi0xLjUKJeLjz9MKMyAwIG9iago8PC9TdWJ0eXBlL0Zvcm0vRmlsdGVyL0ZsYXRlRGVjb2RlL1R5cGUvWE9iamVjdC9NYXRyaXggWzEgMCAwIDEgMCAwXS9Gb3JtVHlwZSAxL1Jlc291cmNlczw8L1Byb2NTZXQgWy9QREYgL1RleHQgL0ltYWdlQiAvSW1hZ2VDIC9JbWFnZUldPj4vQkJveFswIDAgMTg5IDE4OV0vTGVuZ3RoIDI3NDg+PnN0cmVhbQp4nL1aQa4lORHcv1P8I7iqXK7yFZBYsGKB2CFAaIw0bLg+zsyIyHyIBRISak1ntCvy93Nk2L9/TP36aT/HO3/Wru3nl49hVvvvl89fP7///P1z/Pzzc/78ZrP+9jnaz28/f/hj+/nT59f963/8Av9d+//pryEr18ls+P2bbb/+8Re1sckq6d9tf8baEmfX5wgOq6+Du9eWOLuOMzisvg7uXlvi7HpfwWH1dXD32hJn196Dw+rr4O61Jc6u1x0cVl8Hd68tcXY9R3BYfR3c4wnurs5tb3BYfT24M+Sdoe4MUVlS2jfUekOsJzRCeVOpEZsfsfc7towycuN37PuObffYLcqde+6x5R47vmKjKD23u1cWn8+f8/HnKL4YtDNEOaEJpHiTTRPBQyFICJFcqBaiOaWamIJN2V1uT1eqFrZP10g+RgPnKHOeZb4T8zWSD9JAe8ukZ5lwrK0kbcBhz9IT3NmCOuMMc94os4nofiBh1+dMY8x0xAxHbIJPf1fMHEWemD+QC2I1STslKsRcnz2tEM9Bq/JKcDb4MTeen2cDfljtkYCOOlZX8gzc+OgJdN6xupJnwI+tPRLQoceIo8FHasBnrKHLBmzwARrPJ7XBnGWQmizoExJNKMRZqhZ5fN7k7MpxsmriMUHnDmzz7mWinDC4HVvs2OGFfbH2sj0/vuTsesLTrDrCsbbE8elz5qWHe8PWgtnSV3CZ0eCk9dl/SfjGQavektvY4JYynvvGgKwiIEthdSXPgKwiIEthdS ......... (continued for 120000 chars )

Re: parse error: premature EOF

Posted: Thu Jun 09, 2022 5:22 pm
by jonboy49
Your third parm makes no sense. If you are using %addr(json:*data) as the second parm then the third should be %len(json) - no need for a trim.

Don't know why it would affect anything though.

Re: parse error: premature EOF

Posted: Fri Jun 10, 2022 7:51 am
by gio.cot
Hi jonboy49

i tried also with this :
docNode = yajl_buf_load_tree(%addr(json:*data) :%len(json):errMsg );
but i have the same problem
Thanks

Re: parse error: premature EOF

Posted: Fri Jun 10, 2022 7:58 pm
by jonboy49
How is the variable json defined? How is it populated? You're giving us very little to work with.

Re: parse error: premature EOF

Posted: Fri Jun 10, 2022 9:17 pm
by gio.cot
Hi jonboy49

Attached the json file that we receive as response, invoking a courier web service
let me know if you need more information.
Thanks in advance
Gio

Re: parse error: premature EOF

Posted: Sat Jun 11, 2022 7:50 am
by jonboy49
I still need what I asked for. How is the variable defined and how is it populated?

P.S. The file you sent is either corrupt or encrypted - it looks nothing like the data you posted earlier.

Re: parse error: premature EOF

Posted: Mon Jun 13, 2022 7:43 am
by Scott Klement
I tried your JSON document with yajl_buf_load_tree, and it worked perfectly for me.

Something is wrong with your code that reads or the json and feeds it into yajl. Since we have no idea how your code works, we can't begin to help you. Provide a complete program that reproduces the problem so we can try it ourselves.

Re: parse error: premature EOF

Posted: Mon Jun 02, 2025 8:18 pm
by serdec
Hi all from Argentina,
I have YAJL installed in production and works very well.

In order to have an indent file with JSON contaning errors, i want wo create a general routine that dynamically reads any JSON and produce an indent output file.

I have my program compiled compiled but with "yajl_buf_load_tree" , i have similar issue .
I look for to hard but , i can't find my error.

This is mi code,

dcl-s jsonInput varchar(1000);
dcl-s docNode pointer;

jsonInput = '{ "nombre": "Juan", "edad": 30, "activo": true }';

docNode =
yajl_buf_load_tree(
%addr(jsonInput):
%len(%trimr(jsonInput)):
errMsg);

and errmsg variable contain= " parse error: premature EOF "

Any help will be much appreciated

Thank you in advance.

Re: parse error: premature EOF

Posted: Sat Jun 07, 2025 12:11 am
by Scott Klement
serdec wrote: Mon Jun 02, 2025 8:18 pm

Code: Select all

dcl-s jsonInput varchar(1000);
dcl-s docNode pointer;

jsonInput = '{ "nombre": "Juan", "edad": 30, "activo": true }';

docNode = 
          yajl_buf_load_tree(
            %addr(jsonInput): 
            %len(%trimr(jsonInput)): 
            errMsg);
change %ADDR(jsonInput) to %ADDR(jsonInput:*data).

I would also remove the %trimr() from the %len(). The trim is not necessary as there are no blanks at the end of jsonInput. If you MUST trim it in another situation, please do the trim earlier in the program, so that when you do %addr() and %len() they are already correct. Trimming direcly on %len() is not good when you're also doing %addr().