Page 1 of 1

DATA-INTO YAJLINTO Parser Data Structures

Posted: Sun Feb 19, 2023 12:42 am
by bbunney
I have gone through the Working with JSON document and have the YAJL Open Source Tool installed. I coded, compiled and ran the YAJLINTO example successfully. I am very familiar with DATA-INTO using it with XML. I've been learning JSON for the past couple of weeks. In the document, it states that data can be nested (arrays inside objects and/or objects inside arrays). I have JSON messages that have objects inside of objects. I'm not sure how to set up the data structures for this.

{"msgHeader":
{"requestor":"SOMEONE",
"transactionID":"84cc6a48-fea9-44a0-9efb-ddf9f357b836",
"transactionName":"TRANSFER",
"transactionTimestamp":"2023-02-12T16:34:07.5631111Z"},
"msgBody":{"propertyCode":"XXX",
"cardNumber":"1080313XX9Z",
"localAccount":"",
"transactionType":"XXX",
"transactionAmt":"00000000150",
"outputName":"OOOXXX01",
"bankCode":"037"}}

I gave it a try. Maybe I don't need the top level DS?

Dcl-Ds request Qualified;
Dcl-Ds msgHeader;
requestor Char(7);
transactionID Char(28);
transactionName Char(10);
transactionTimestamp Char(28);

Dcl-Ds msgBody;
propertyCode Char(3);
cardNumber Char(11);
localAccount Char(7);
transactionType Char(3);
transactionAmt Char(11);
outputName Char(10);
bankCode Char(3);
End-Ds;
End-Ds;
End-Ds;

Re: DATA-INTO YAJLINTO Parser Data Structures

Posted: Sun Feb 19, 2023 5:04 pm
by jonboy49
I don't see the point in the outer DS. Apart from that it look about right.

Two things:

1) Please use code tags around your RPG code. Your post lost all indentation and was hard to read.

2) in the YAJL library you will find the command YAJLGEN. This will generate a skeleton program (including the target DS) from a JSON file. You will have to change sizes, etc. (and I change the names to mixed case). I always use this even if just as a check of whT I CODED MYSELF.

Re: DATA-INTO YAJLINTO Parser Data Structures

Posted: Sun Feb 19, 2023 10:20 pm
by bbunney
YAJLGEN is awesome! Thank you so much! It generated 3 data structures with the only difference being that body was not nested within header. The code ran fine. Could you show me an example of putting code tags around source code please? I saw in the FAQ's you can't use HTML but you can use BBCode which I know nothing about currently. Thanks!

Re: DATA-INTO YAJLINTO Parser Data Structures

Posted: Sun Feb 19, 2023 10:58 pm
by jonboy49
Best way is to show you where to look. You can highlight a code block and then click the icon shown or
CodeTagsForBB.png
CodeTagsForBB.png (52.03 KiB) Viewed 2317 times
You can manually code the tags the way they appear in the image i.e. a code tag followed by the code sample followed by a /code tag. All tags must be surrounded by square brackets [ ] like that.

Glad that the tool worked for you.

Re: DATA-INTO YAJLINTO Parser Data Structures

Posted: Mon Feb 20, 2023 4:46 am
by bbunney
Thank you for your help. I really appreciate it. I will be showing the other programmers I work with how this works.