Page 1 of 1

YAJL function for deleting node

Posted: Wed Jan 10, 2024 6:38 pm
by Isca
Hello everyone,

I'm starting with JSON manipulation and I need to modify a JSON by removing nodes from a list.
I wanted to know if there is an equivalent to yajl_array_delete in RPG 4, or other solutions?

Thanks in advance.

Re: YAJL function for deleting node

Posted: Wed Jan 10, 2024 7:35 pm
by jonboy49
Directly within RPG your only option would be to use DATA-INTO with YAJLINTO to read the json, then copy only the required portions to a new DS and use DATA-GEN with YAJLGEN to regenerate the json. It is possible that you could achieve this without the use of a second DS by utilizing countprefix and setting the count for the array to zero.

I see no sign of the function yajl_array_delete - do you have the right name?

Re: YAJL function for deleting node

Posted: Thu Jan 11, 2024 9:11 pm
by Scott Klement
Something like this could be written, but it is an unusual request.

People normally store their records in a database or similar, not in a JSON document. Typically, your JSON document is created from the database on-the-fly when it is needed.

So if you had elements to delete, you'd delete them from the database. When you generate your JSON, they wouldn't be there because you generated from the database.

You might say the JSON document is an ephemeral document. It's typically just generated, sent over a network, and interpreted -- all within a second -- and that's the complete life of the document.