Data-Into loses embedded blanks

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
Alan5432
Posts: 5
Joined: Mon Sep 26, 2022 10:03 pm

Data-Into loses embedded blanks

Post by Alan5432 »

I have a JSON element that will contain some Y/N flags, but there can be embedded blanks in the string.
"Flags": "YNNYN Y"

My data structure allows a string of up to 40 characters:
DS
Flags char(40);

My issue is that after the Data-Into the value in Flags is this:
Flags = 'YNNYN Y '

It has compressed all the extra spaces and only leaves one.

I've done other tests and the results are similar.
"Flags": "A B C D"

after the Data-Into
Flags = 'A B C D '

I did try using the yajl_object_find and yajl_get_string and it retains the exact same string from the JSON (no compression).

Has anyone else run into this behavior? I thought everything inside the double quotes would be preserved exactly as it was presented in the JSON.
Scott Klement
Site Admin
Posts: 635
Joined: Sun Jul 04, 2021 5:12 am

Re: Data-Into loses embedded blanks

Post by Scott Klement »

Hiya Alan,

Thanks for reaching out. The RPG DATA-INTO opcode has an option called 'trim' that can be used to trim blanks. I'm referring to the TRIM option of the %DATA built-in function (not to be confused with the %TRIM built-in function.)

Many people don't realize that in addition to trimming off the leading/trailing blanks, it also consolidates the blanks in the middle of strings.

Details here:
https://www.ibm.com/docs/en/i/7.4?topic ... ll#trimopt

If you set it to trim=none, it should stop trimming them. (You may have to trim leading/trailing blanks manually if desired.)
Post Reply