× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



In node.js javascript you will write something simple as this (unless you
can have more sections and need a loop):

myObj = JSON.parse(yourJSON)

secOne = JSON.serialize(myObj.items[0])
fs.writeFile('/mySecOne.json',secOne','utf8')

secTwo = JSON.serialize(myObj.items[1])
fs.writeFile('/mySecTwo.json',secTwo','utf8')

My point is - use the right tool to the job, in this case node.js and the
use some of the
large number of free stuff avaiable - in this case profounds NPM to call
node.js from
RPGLE.







On Fri, Sep 15, 2017 at 6:06 PM, Slanina, John <jslanina@xxxxxxxxxx> wrote:

Here is the data, so what I want is each "Items" array element aka VAL in
my source. dow YAJL_ARRAY_LOOP( items : i: VAL );
I want to convert back to a string

{
"found": true,
"nextPage": "170915-560,5",
"items": [{
"eventType": "customerInventoryUpdated",
"time": "2017-09-15 14:02:38",
"user": "jslanina",
"inventoryDetails": {
"inventoryId": 28286221,
"status": "deinstalled",
"serialNumber": "74U2X47BS105609"
},
"activityDetails": {
"activityId": 6517448,
"resourceId": "81093",
"resourceInternalId": 648,
"date": "2017-09-15",
"apptNumber": "12384584",
"customerNumber": "31695901"
},
"inventoryChanges": {
"exchangedInventoryId": 0
}
},
{
"eventType": "inventoryUndoInstall",
"time": "2017-09-15 14:02:38",
"user": "jslanina",
"inventoryDetails": {
"inventoryId": 28286085,
"status": "resource",
"inventoryType": "SERIALIZED",
"serialNumber": "ABJBPA48B370608"
},
"activityDetails": {
"activityId": 6517448,
"resourceId": "81093",
"resourceInternalId": 648,
"date": "2017-09-15",
"apptNumber": "12384584",
"customerNumber": "31695901"
},
"inventoryChanges": {
"status": "resource",
"exchangedInventoryId": 0
}
}],
"links": [{
"rel": "describedby",
"href": "https://api.etadirect.com/
rest/ofscCore/v1/metadata-catalog/events"
},
{
"rel": "canonical",
"href": "https://api.etadirect.com/
rest/ofscCore/v1/events/?limit=10&page=170915-560,3"
},
{
"rel": "next",
"href": "https://api.etadirect.com/
rest/ofscCore/v1/events/?limit=10&page=170915-560,5"
}]
}

First one
{
"eventType": "customerInventoryUpdated",
"time": "2017-09-15 14:02:38",
"user": "jslanina",
"inventoryDetails": {
"inventoryId": 28286221,
"status": "deinstalled",
"serialNumber": "74U2X47BS105609"
},
"activityDetails": {
"activityId": 6517448,
"resourceId": "81093",
"resourceInternalId": 648,
"date": "2017-09-15",
"apptNumber": "12384584",
"customerNumber": "31695901"
},
"inventoryChanges": {
"exchangedInventoryId": 0
}
}

Second one
{
"eventType": "inventoryUndoInstall",
"time": "2017-09-15 14:02:38",
"user": "jslanina",
"inventoryDetails": {
"inventoryId": 28286085,
"status": "resource",
"inventoryType": "SERIALIZED",
"serialNumber": "ABJBPA48B370608"
},
"activityDetails": {
"activityId": 6517448,
"resourceId": "81093",
"resourceInternalId": 648,
"date": "2017-09-15",
"apptNumber": "12384584",
"customerNumber": "31695901"
},
"inventoryChanges": {
"status": "resource",
"exchangedInventoryId": 0
}
}

-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Jon
Paris
Sent: Friday, September 15, 2017 11:05 AM
To: Rpg400 Rpg400-L
Subject: Re: Convert JSON object to String.

Can you post the related JSON and identify what you mean by "VAL" - your
code references val as a node identifier and you appear to be extracting
individual elements from it.

Do you mean that you want the actual JSON string? i.e. inclusive of all
the elements within it?


Jon Paris

www.partner400.com
www.SystemiDeveloper.com

On Sep 15, 2017, at 10:28 AM, Slanina, John <jslanina@xxxxxxxxxx> wrote:

Bradley,

It is a web service call using RXS-XML library the whole JSON Document
comes back in a string.
With I then I do this code.

But I want the array element node "VAL" to be logged not docnode.

docNode = yajl_buf_load_tree(%addr(gXmlResponse:*data) :
%len(gXmlResponse) : JsonErrMsg);
Node = YAJL_object_find(docNode : 'found');

if YAJL_IS_TRUE(Node);
//
// Update NextPage
//
chain (Subscription_P) ofsupd01 ofsupd01Ds;
if not %found(ofsupd01);
exsr Exitpgm;
endif;

Node = YAJL_object_find(docNode : 'nextPage');
nextPage = YAJL_get_string(Node);

ofsupd01Ds.nextPage = nextPage;
ofsupd01Ds.LastPollDate = %dec(%date():*cymd);
ofsupd01Ds.LastPollTime = %dec(%Time():*ISO);
ofsupd01Ds.LastPollStatus = 'G';

update ofsup01f ofsupd01Ds;

items = YAJL_object_find(docNode: 'items');

i = *zeros;

dow YAJL_ARRAY_LOOP( items : i: val );
Node = YAJL_object_find(Val : 'eventType');
eventType = YAJL_get_string(Node);

clear oftrtv01Ds;
chain (Subscription_P : eventType) oftrtv01 oftrtv01Ds;
if %found(oftrtv01);
if oftrtv01Ds.Program <> 'NA' and oftrtv01Ds.status = 'A';
monitor;
writeJobLog('Calling ' + %trim(eventType) + ' ' +
%trim(oftrtv01Ds.Program) + X'25');
program(eventType : val );
on-error;
writeJobLog('*** ERROR *** Calling ' + %trim(eventType) + ' '
+
%trim(oftrtv01Ds.Program) + X'25');
endmon;
endif;
endif;
enddo;
endif;


Val is the one I want to convert to a string which is an Object not a
string .



-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of
Bradley Stone
Sent: Friday, September 15, 2017 9:48 AM
To: RPG programming on the IBM i (AS/400 and iSeries)
Subject: Re: Convert JSON object to String.

John,

How are you getting the JSON data into your program? From a POST using
standard input?


Bradley V. Stone
www.bvstools.com
MAILTOOL Benefit #12 <https://www.bvstools.com/mailtool.html>: Both
Text and HTML email support

On Fri, Sep 15, 2017 at 8:11 AM, Slanina, John <jslanina@xxxxxxxxxx>
wrote:

Does anyone know using Scott Klement Json Library how you can convert
an JSON object back to a string so I can log the file ?

I have a json array and I want to log each element within the array
to a file.

Thanks
John Slanina
--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email:
RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list
options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx 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: http://amzn.to/2dEadiD

--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx 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: http://amzn.to/2dEadiD
--
This is the RPG programming on the IBM i (AS/400 and iSeries)
(RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx 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: http://amzn.to/2dEadiD

--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
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: http://amzn.to/2dEadiD
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
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: http://amzn.to/2dEadiD





As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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

This mailing list archive is Copyright 1997-2024 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].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.