ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

.json Array problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • .json Array problem

    I received this .json validation error response to an API POST

    [
    {
    "success": false,
    "data": null,
    "statusSet": [
    {
    "code": 100,
    "descriptor": "Required",
    "message": "LoadNumber required",
    "field": "LoadNumber"
    }
    ]
    }
    ]

    I used Scott's YAJLGEN command to generate this data structure


    dcl-ds errType2 qualified dim(5);
    num_errType2 int(10) inz(0);

    success ind;
    data varchar(5) inz('');

    num_statusSet int(10) inz(0);
    dcl-ds statusSet dim(10);
    code packed(7) inz(0);
    descriptor varchar(15) inz('');
    message varchar(128) inz('');
    field varchar(9) inz('');
    end-ds;
    end-ds;

    As generated, 'num-errType2...' preceded the dcl-ds, but this caused a compile error RNF5347, An assignment operator is expected with the EVAL operation.

    Here is the code I am using to process the response

    for i = 1 to errType2.num_ErrType2;
    for j = 1 to errType2.num_statusSet;
    srcDta = errType2.statusSet(j).message + crlf;
    write emailbody msgBody;
    endfor;
    endfor;
    I am getting compile error RNF5343, Array ERRTYPE2 has too many omitted indexes at lines 'for i = 1 ...', 'for j = 1 ...', and 'srcDta = ...'.

    I'm stumped. Can anyone help?


  • #2
    errType2 is an array, so you have to provide an index to say which element you want to use.
    Code:
    errType2(i).num_statusSet
    rrType2(i).statusSet(j).message
    When you specify an array for DATA-INTO, the number of array elements that were set by DATA-INTO is in the PSDS. The num_ subfields are for counting other subfields within the data structure. You should remove the num_errType2 subfield from the data structure.
    Code:
    dcl-ds pgmStatus psds qualified;
       num_elements int(20) pos(372);
    end-ds;
    DATA-INTO statusSet ...
    for i = 1 to pgmStatus.num_elements;
       ...

    Comment

    Working...
    X