utilizing an unnamed array of objects
Posted: Mon Jun 13, 2022 3:22 pm
I can't figure out how to specify the number of objects in this example. This is a very simplified(one element) example of what I am dealing with. This is a 3rd party API I am trying to communicate with and I need from one to three dimentioned objects in one json, but I don't want an empty object to be sent in this example. I can think of some work arounds but thought I'd check here, I just can't find anything in the documentation that addresses this nameless array scenario.
Contents of smallexample.json
The data-into loads the data structure as expected. however the num_jsonDoc doesn't get populated
because it is not part of the data structure.
Note: I used YAGLGEN to create this program(except that I added the data-gen to demonstrate the result.
YAJLGEN created the num_jsonDoc on a line without the Dcl-S, I added that to get it to compile
In this case I want to have up to a dim of 3 of the json objects contained within the unnamed array
The DATA-GEN creates three instead of two objects because I don't know where to put the num_jsonDoc element
within the data structure.
Any help would be much appreciated. Thanks
p.s. it looks like the yajl version is from Aug 2020. Not sure how to find the version number
Contents of smallexample.json
Code: Select all
[
{
"ShipmentID": 100
},
{
"ShipmentID": 200
}
]
Code: Select all
**FREE
ctl-opt dftactgrp(*no);
readTheJson();
*inlr = *on;
dcl-proc readTheJson;
Dcl-S num_jsonDoc int(10) inz(0); // Modified to add Dcl-S
dcl-ds jsonDoc qualified dim(3);
SHIPMENTID packed(3) inz(0);
end-ds;
Dcl-S Request Varchar(5000);
Dcl-S ifsPathName varchar(5000);
ifsPathName = '/temp/smallexample.json';
data-into jsonDoc %DATA( ifsPathname
: 'doc=file case=convert countprefix=num_')
%PARSER( 'YAJLINTO'
: '{ "document_name": "jsonDoc", +
"number_prefix": "YAJL_" }');
DATA-GEN jsonDoc %Data( Request : 'countprefix=num_ trim=all' )
%Gen( 'YAJLDTAGEN');
Return;
end-proc;
because it is not part of the data structure.
Note: I used YAGLGEN to create this program(except that I added the data-gen to demonstrate the result.
YAJLGEN created the num_jsonDoc on a line without the Dcl-S, I added that to get it to compile
In this case I want to have up to a dim of 3 of the json objects contained within the unnamed array
The DATA-GEN creates three instead of two objects because I don't know where to put the num_jsonDoc element
within the data structure.
Code: Select all
[{"SHIPMENTID":100},{"SHIPMENTID":200},{"SHIPMENTID":0}]
p.s. it looks like the yajl version is from Aug 2020. Not sure how to find the version number