Page 1 of 1

#XPRIM_JsonObject

Posted: Fri Mar 22, 2019 3:59 pm
by soa
I'm calling a web service which returns an array of objects like this

{
"SchoolsList": [
{
"Account": "f488553b-d025-dc11-803a-00118581f25d",
"AccountName": "Vistara Primary School",
"DECId": null,
"NESAId": "77579"
},
{
"Account": "a2251935-80fa-da11-8d33-00118581f25d",
"AccountName": "Giant Steps Sydney",
"DECId": null,
"NESAId": "11837"
},

There are almost 4000 items in this list and it take 2 minutes to read from beginning to end and extract the 4 fields. This seems like a long time for an essentially in memory operation on a big fast iseries. it took less than 2 seconds to retrieve the data.

I'm doing (see below). Is there a faster way to do this?

Define_Com Class(#XPRIM_JsonReader) Name(#Reader)
Define_Com Class(#XPRIM_JsonObject) Name(#Item) Reference(*DYNAMIC)

#Reader.SetSourceHttpResponse Httpresponse(#Request.Response) Errorinfo(#ErrorInfo)
#Reader.ReadBeginArray Found(#OK)
#Reader.MoveNext Ok(#OK)

Dowhile Cond(#OK *And (*Not #Reader.IsEndArray))
#Reader.ReadObject Found(#OK) Result(#Item)
If Cond(#OK)

#WRK50A := #item.GetString( 'Account' ).AsNativeString
#SCHLNM := #item.GetString( 'AccountName' ).AsNativeString
#wrk5n0 := #item.GetNumber( 'DECId' )
#wrk6n0 := #item.GetNumber( 'NESAId' )


Endif

#Reader.MoveNext Ok(#OK)
Endwhile

Re: #XPRIM_JsonObject

Posted: Fri Mar 22, 2019 4:35 pm
by tsupartono
The XPRIM_JsonReader will not perform well when reading large amount of data, as it's an RDML library, as opposed to a native VL feature. Performance on IBM i is definitely worse than on Windows.

My suggestion would be to try to use the native PRIM_JSON feature.
You would need to write the response to a temporary file first.
See example below.
If you have any question about PRIM_IOC.FileStream, PRIM_IOC.StreamReader, or PRIM_JSON.Reader, please post on the forum as a new topic.

Code: Select all

Define_Com Class(#PRIM_IOC.FileStream) Name(#FileStream)
Define_Com Class(#PRIM_IOC.StreamReader) Name(#TextReader) Stream(#FileStream)
Define_Com Class(#PRIM_JSON.Reader) Name(#JsonReader) TextReader(#TextReader)
Define_Com Class(#XPRIM_File) Name(#TempFile)

* Create empty temporary file
#TempFile.CreateTemporaryFile

* Save HTTP response to temporary file
#HttpRequest.Response.AsFile AutoDelete(True) Path(#TempFile)

* Do the reading using JsonReader
#FileStream.Path := #TempFile

Dowhile Cond(#JsonReader.Read)
   * DO your stuff here
Endwhile

Re: #XPRIM_JsonObject

Posted: Mon Mar 25, 2019 5:31 pm
by soa
See my response elsewhere in this forum. #PRIM_JSON.Reader is MUCH faster than #XPRIM_JSON.Reader