YAJL_BUF_LOAD_TREE Handling Null Values

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
kathan.p@gmail.com
Posts: 19
Joined: Wed Aug 04, 2021 7:27 pm

YAJL_BUF_LOAD_TREE Handling Null Values

Post 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?
Last edited by kathan.p@gmail.com on Tue Aug 10, 2021 7:50 pm, edited 1 time in total.
Scott Klement
Site Admin
Posts: 666
Joined: Sun Jul 04, 2021 5:12 am

Re: YAJL_BUF_LOAD_TREE Handling Null Values

Post 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,
kathan.p@gmail.com
Posts: 19
Joined: Wed Aug 04, 2021 7:27 pm

Re: YAJL_BUF_LOAD_TREE Handling Null Values

Post 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
kathan.p@gmail.com
Posts: 19
Joined: Wed Aug 04, 2021 7:27 pm

Re: YAJL_BUF_LOAD_TREE Handling Null Values

Post 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!!
Post Reply