Re: Error Reading JSON using Data-INTO
Jon Paris <[email protected]>
| Newsgroups | gmane.comp.systems.as400.web |
|---|---|
| Message-ID | <[email protected]> |
As Charles indicted you are not mapping the json correctly.
data is an element _within_ the target DS as is title. So it needs to look like this:
dcl-ds parsedData qualified;
dcl-ds data;
instruction2 char(50);
...
end-ds;
title char(50);
end-ds;
Then your Data-Into becomes:
Data-into parsedData %Data(JsonString:'case=convert') %PARSER('YAJL/YAJLINTO');
Because (unlike XML) json does not have a named outer element, DATA-INTO will just accept the name of the DS you target as if it were the root element name.
Notice also that (in this case) there is no need for allowextra BUT you do need some form of case= and since json can use non-RPG characters in names using =convert is a good choice - although in this case case=any would have worked as there are no special characters in the names.
Jon Paris
> On Aug 4, 2021, at 5:19 PM, Charles Wilt <[email protected]> wrote:
>
> Your JSON doc is a little wonky...
>
> Thing to keep in mind is that the root of a JSON doc isn't named. "Data"
> is actually the name of a json object in your document.
>
> the ds you need is like so
>
> dcl-ds doc;
> dcl-ds data;
> ...
> end-ds;
> end-ds;
>
> Data-into doc %Data(JsonString:'allowextra=yes') %PARSER('YAJLINTO');
>
> HTH,
> Charles
>
>
> On Wed, Aug 4, 2021 at 3:07 PM Kathan Pandya <[email protected]> wrote:
>
>> Hi,
>>
>> I am new to YAJL and using DATA-INTO. I have a simple json and I am trying
>> to read it using DATA-INTO and getting below error:
>> Cause . . . . . : While parsing a document for the DATA-INTO operation, the
>> parser found that the document does not correspond to RPG variable "data"
>> and the options do not allow for this. The reason code is 4. The exact
>> subfield for which the error was detected is "data.instruction2". The
>> options are "allowextra=yes". The document name is *N; *N indicates that
>> the
>> document is not an external file. The parser is 'YAJLINTO'. *N indicates
>> that the parser is a procedure pointer.
>>
>> JSON -
>> {
>> "data": {
>> "instruction2": "FIRST SEAT",
>> "seat1l3": "2356",
>> "reset34": "Yes",
>> "temp": "-78",
>> "seat1l4": "326",
>> "seat2l3": "3265",
>> "instruction1": "** Daily Check Call **",
>> "seat2l4": "986",
>> "trl": "12345",
>> "seat2a70": "253",
>> "seat1a70": "895",
>> "eta": "2021-08-18T11:23:24-07:00",
>> "onsched": "Yes",
>> "hub": "896586",
>> "odo": "123658",
>> "reasonoffsched": "traffic"
>> },
>> "title": "Daily Check Call - 01"
>> }
>>
>>
>> RPG Declaration -
>>
>> dcl-ds data qualified;
>> instruction2 char(50);
>> seat1l3 char(5);
>> reset34 char(1);
>> temp char(3);
>> seat1l4 char(5);
>> seat2l3 char(5);
>> instruction1 char(50);
>> seat2l4 char(5);
>> trl char(6);
>> seat2a70 char(5);
>> seat1a70 char(5);
>> eta char(26);
>> onsched char(1);
>> hub char(7);
>> odo char(11);
>> reasonoffsched char(70);
>> title char(50);
>> end-ds;
>>
>> I am moving the data into a standalone character variable name JsonString
>> (using it below in Data-INTO)
>>
>> Statement -
>> Data-into data %Data(JsonString:'allowextra=yes') %PARSER('YAJLINTO');
>>
>>
>> Please advise what am I doing wrong?
>> --
>> This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing
>> list
>> To post a message email: [email protected]
>> To subscribe, unsubscribe, or change list options,
>> visit: https://lists.midrange.com/mailman/listinfo/web400
>> or email: [email protected]
>> Before posting, please take a moment to review the archives
>> at https://archive.midrange.com/web400.
>>
>>
> --
> This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list
> To post a message email: [email protected]
> To subscribe, unsubscribe, or change list options,
> visit: https://lists.midrange.com/mailman/listinfo/web400
> or email: [email protected]
> Before posting, please take a moment to review the archives
> at https://archive.midrange.com/web400.
>
--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/web400
or email: [email protected]
Before posting, please take a moment to review the archives
at https://archive.midrange.com/web400.