Jon,

Thanks for taking the time and making the effort to get this to work. I was able to get this simple example to work and apply it to a much more complex object. Worked flawlessly!

Thanks!

- Ryan Cronin

-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Jon Paris
Sent: Sunday, January 13, 2019 12:34 PM
To: RPG programming on the IBM i (AS/400 and iSeries) <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: Handling JSON object/array nulls in DATA-INTO

OK - this seems to work for both cases.

It seems to need the allowextra=yes - assumedly because in the null case I guess a value is being returned by the parser that has nowhere to go.

I had hoped that coding a count_ on the parms DS would result in the compiler not treating the fields within the DS as being missing, but that doesn't seem to work. Personally that seems like a bug to me because using a count should tell the compiler that it is OK if an element is missing. If the element is missing then clearly any of its subfields will always be missing - but that doesn't seem to be the way it works. Hopefully Barbara can comment on this and tell us if this is indeed a bug or if it is working as designed and an RFE is needed. This is not a situation that can occur in XML so perhaps it was not considered.

I added counts to all of the individual fields within parms to avoid having to use allowmissing=yes.

Here's the code:


Ctl-Opt DFTACTGRP(*NO) Option(*SrcStmt);

dcl-s pathJson varchar(1000);

dcl-ds pathDS qualified;
path varchar(100);
timeout int(10);
size int(10);
dcl-ds parms;
count_customer_id int(5);
customer_id int(10);
count_invoice_id int(5);
invoice_id int(20);
count_due_date int(5);
due_date char(10);
count_total_charges int(5);
total_charges zoned(7:2);
end-ds;
end-ds;


pathJson = '{ +
"path": "/path/on/ifs.txt", +
"timeout": 0, +
"size": 128, +
"parms": { +
"customer_id": 123, +
"invoice_id": 12348, +
"due_date":"2019-03-10", +
"total_charges":1234.34 +
} +
}';


data-into pathDS
%data(pathJson:'case=any allowextra=yes countprefix=count_')
%parser('YAJL/YAJLINTO');

pathJson = '{ +
"path": "/path/on/ifs.txt", +
"timeout": 0, +
"size": 128, +
"parms": null +
}';

data-into pathDS
%data(pathJson: 'case=any allowextra=yes countprefix=count_')
%parser('YAJL/YAJLINTO');

*inlr = *on;


Jon Paris

www.partner400.com
www.SystemiDeveloper.com

On Jan 11, 2019, at 11:09 AM, Ryan Cronin <rcronin@xxxxxxxxxxxxxxxxx> wrote:

Hello,

I have the following JSON example that is causing some issues with the DATA-INTO feature.

JSON:
dcl-s json varchar(1000) inz('{"path": "/test/34234234.pdf",
"timeout": 0, "parms": null}');

RPG:
dcl-ds pathDS qualified;
path varchar(200);
timeout int(10);
dcl-ds parms;
type varchar(100);
size int(10);
end-ds
end-ds;

data-into pathDS %data(json:'case=any allowmissing=yes')
%parser('YAJLINTO');


Does anyone have any advice on how to get this to work properly?

Thanks,

Ryan Cronin
--
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


This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].