I saved your snippet below as dons.json and opened it with firefox. It appears to create an implied index (name) for api_product_list_json like this:
0: "P2P Rideshare API Product"
Greg
-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxxxxxxxx] On Behalf Of Greg Wilburn
Sent: Friday, January 11, 2019 8:18 AM
To: RPG programming on the IBM i (AS/400 and iSeries) <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: RE: DATA-INTO Json failing
Don,
I found that putting the JSON into Notepad++ with the JSON add-in was huge help in determining the structure of a JSON document.
You could also open it in something like Firefox.
Greg
-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxxxxxxxx] On Behalf Of Don Brown
Sent: Thursday, January 10, 2019 5:15 PM
To: RPG programming on the IBM i(AS/400 and iSeries) <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: DATA-INTO Json failing
Thanks Barbara,
I have tried quite a few combinations and still receive the error indicating the data structure is not correct
PTF SI68421 is installed on my system.
This is the line in the json that is causing the problems; "api_product_list_json" : [ "P2P Rideshare API Product" ],
To me this is saying it is an array because of the [ brackets but there is only one name in the array with no value ? Or is that the value with no name ?
The error confirms that is the line causing the issue;
Message ID . . . . . . : RNX0356
Message . . . . : The document for the DATA-INTO operation does not
match
the RPG variable; reason code 6.
Cause . . . . . : While parsing a document for the DATA-INTO operation,
the
parser found that the document does not correspond to RPG variable "aaaaa"
and the options do not allow for this. The reason code is 6. The exact
subfield for which the error was detected is
"aaaaa.api_product_list_json(1)". The options are "case=convert
countprefix=num_". The document name is *N; *N indicates that the document
is not an external file. The parser is 'YAJL72/YAJLINTO'. *N indicates that
the parser is a procedure pointer.
I have pasted the entire program below which should compile and run.
How should I be defining the data structure to parse this json string ?
H DFTACTGRP(*NO)
dcl-ds aaaaa qualified;
refresh_token_expires_in varchar(10);
api_product_list varchar(50) ;
num_api_product_list_json int(10) ;
dcl-ds api_product_list_json dim(5);
api_product_list_json varchar(50) ;
// P2P_Rideshare_API_Product varchar(50) ;
end-ds ;
organization_name varchar(50);
developer_email varchar(50);
token_type varchar(50);
issued_at varchar(20);
client_id varchar(50);
access_token varchar(50);
application_name varchar(50);
scope varchar(50);
expires_in varchar(10);
refresh_count varchar(10);
status varchar(20);
end-ds;
D myjson s 5000a varying
/free
myjson = '{ +
"refresh_token_expires_in" : "0", +
"api_product_list" : "[P2P Rideshare API Product]", +
"api_product_list_json" : [ "P2P Rideshare API Product" ], +
"organization_name" : "onegov", +
"developer.email" : "sam@xxxxxxxxx", +
"token_type" : "BearerToken", +
"issued_at" : "1547071634302", +
"client_id" : "WmTFrOi8ZXBa0RBn6Tx2vYd3dnkOgtjj", +
"access_token" : "ePpNwfSoCUosyHpqQJlcK3zAjHeG", +
"application_name" : "2d8ee44d-5621-459a-8e44-7946c8d319dd", +
"scope" : "", +
"expires_in" : "43199", +
"refresh_count" : "0", +
"status" : "approved" +
}';
data-into aaaaa %data( myjson :
'case=convert countprefix=num_')
%Parser( 'YAJLINTO' );
*inlr = *on;
/end-free
/free
Don Brown
"RPG400-L" <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> wrote on 10/01/2019
10:33:09 PM:
From: "Barbara Morris" <bmorris@xxxxxxxxxx>
To: rpg400-l@xxxxxxxxxxxx
Date: 10/01/2019 10:33 PM
Subject: Re: DATA-INTO Json failing
Sent by: "RPG400-L" <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx>
On 2019-01-10 1:34 AM, Don Brown wrote:
I am hoping someone can advise how I need to create the data
structure
of
DATA-INTO with this json string.
...
But the following line api_product_list_json is an array but it has
no elements ?
...
{
"refresh_token_expires_in" : "0",
"api_product_list" : "[P2P Rideshare API Product]",
"api_product_list_json" : [ "P2P Rideshare API Product" ],
...
data-into aaaaa %data( myjson : 'case=convert')
%Parser( 'YAJL72/YAJLINTO' );
This fails to load the "api_product_list_json" : [ "P2P Rideshare
API
Product" ],
...
You said that api_product_list_json has no elements, but your json has
one element for the array.
Since you only have one element, and you have DIM(5) in the data
structure, you would need to either specify option allowmissing=yes,
or better, add a subfield num_api_product_list_json to your data
structure,
and specify option countprefix=num.
But if you do actually have an empty array in the json, there was a
bug in DATA-INTO where it didn't handle an empty array. You need 7.2
PTF
SI68422 or 7.3 PTF SI68421 to fix that.
--
Barbara
--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related
questions.
Help support midrange.com by shopping at amazon.com with our affiliate
link:
https://amazon.midrange.com
______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud
service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________
______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit
http://www.symanteccloud.com ______________________________________________________________________
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
https://amazon.midrange.com
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
https://amazon.midrange.com
As an Amazon Associate we earn from qualifying purchases.