Page 1 of 1

YAJL_BUF_LOAD_TREE Handling Null Values

Posted: Tue Aug 10, 2021 7:25 pm
by kathan.p@gmail.com
I am reading JSON using YAJL_BUF_LOAD_TREE to load the JSON and then read the data using YALJ_GET_STRING/NUMBER.

But when loading the JSON data which is having either NULL/blanks values, it is erroring out with a error message
"lexical error: invalid char in json text"

Code: Select all

{"data":{
"trdate6":null,
"trdate7":null,
"trdate9":null,
"arvtime2":"09/10/2021",
"morestop2":"Yes"}}

Code: Select all

docNode = yajl_buf_load_tree(%Addr(PLPAYLOD):
            %len(%trim(PLPAYLOD)):ErrMsg);
            


Is there a way to handling it?

Re: YAJL_BUF_LOAD_TREE Handling Null Values

Posted: Tue Aug 10, 2021 7:46 pm
by Scott Klement
This is an invalid JSON document. If unsure, you can use the website https://jsonlint.com/ to check your document and see if it's valid.

It's not valid to have a json element with no value like this: "trdate9": ,

You would need to change that to: "trdate9": null,

Re: YAJL_BUF_LOAD_TREE Handling Null Values

Posted: Tue Aug 10, 2021 7:52 pm
by kathan.p@gmail.com
It was typing error it is coming with NULL in field.. but when i check in debug mode it showing blanks.. and the it gives me that error

Re: YAJL_BUF_LOAD_TREE Handling Null Values

Posted: Tue Aug 10, 2021 8:06 pm
by kathan.p@gmail.com
Found the issue.. Before it actual goes to YAJL_LOAD* , a procedure is called to remove the null that's why it is failing. Fixed it and now it working!!

Thanks!!