IBM / db2sock-ibmi

An asynchronous PASE Db2 and IBM i integration library
MIT License
4 stars 7 forks source link

Output parsing issue containing JSON string as value #12

Closed kadler closed 6 years ago

kadler commented 6 years ago

Original report by Brian Jerome (Bitbucket: bjerome, GitHub: brianmjerome).


I am calling a program that returns a JSON string, but using the SQL400Json while testing is not returning the correct output. It also looks like one of the input parameters is coming back when it shouldn't -- I thought this was fixed recently but it might be because of this other issue?

Input

#!json
{"pgm":[
  {"name":"GETJSONDATA",  "lib":"DB2JSON"},
  {"ds": [{"name":"REQPARMS", "dim":1, "by":"in"},
    {"s": [
      {"name":"TEST1", "type":"6p0", "value":1},
      {"name":"TEST2", "type":"12p0", "value":12345678}
    ]}
  ]},
  {"ds": [{"name":"JSONDATA", "dim":100, "by":"out", "dou":"JSONCOUNT"},
    {"s": [
      {"name":"JSONDATA", "type":"64000a"}
    ]}
  ]},
  {"s": {"name":"JSONCOUNT", "type":"10i0", "by":"out", "setlen":"JSONDATA"}},
  {"s": {"name":"RTRNCD", "type":"8a", "by":"out"}}

Output

#!json
{"script":[{"pgm":["GETJSONDATA","DB2JSON",{"REQPARMS":[]},{"JSONDATA":[[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}],[{"JSONDATA":""}]]},{"JSONCOUNT":64000},{"RTRNCD":""}]}]}

The JSONDATA field in the JSONDATA DS should contain a JSON String. It's weird that the JSONCOUNT is coming back as 64000 -- i'm expecting it to come back as 2.

kadler commented 6 years ago

Original comment by Brian Jerome (Bitbucket: bjerome, GitHub: brianmjerome).


In this case I was the messenger with not enough data to reproduce the issue so I'm going back to square one to see if it is another issue -- this will be closed. If it arises again, I'll open a new issue with more/better data. Thanks.

kadler commented 6 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


Mmm ... i hope i was not to harsh. I really do want you to feel you can open an issue. Sometimes a geek (like me), must assert a critical eye to 'random clues' when no other data is available to work a true theory.

Live long and prosper.

kadler commented 6 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


I wait until you have better understanding of RPG you are calling. Aka, i don't think it looks right even a little bit for production RPG. Sorry. (Reminder i am not working Thr or Fri).

kadler commented 6 years ago

Original comment by Brian Jerome (Bitbucket: bjerome, GitHub: brianmjerome).


No sorry the example was just for structure -- it wasn't anything to take verbatim.

kadler commented 6 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


I will get some help on that and report back.

Q1. Is REQPARMS ds structure dim(1)??? This very, very, very, unlikely.

Q1.1) Does REQPARMS ds only have two elements test1, test2??? This seems very, very, very, unlikely. Production code would never have things called test1, tes2. I suspect this is not at all what REQPARMS looks like.

Q2. Is JSONDATA ds structure dim(100)??? This is also unlikely (more possible).

Q2.1) Does JSONDATA ds structure really have only one gigantic character element. JSONDATA.JSONDATA is one huge 64000a (bb)?? I find this very unlikely.

Q3. is RTRNCD actually 8a?? Possible, but modern RPG return code may be int or packed?

Uf da!!!

You see my problem here ... you are claiming RPG 'illiterate' ... and everything in your json looks completely wrong for RPG production code (The RPG has been running for years working properly in our production environment.). Uf Da!!

kadler commented 6 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


I don't write the RPG ... hasn't been an issue until trying to call a PGM with this parser.

Ok then (newbie RPG person).

Best course action is to assume you incorrectly "mapped" RPG to the json to save time. This is not arrogance on my part, but simply truth of years of toolkit and RPG calling. Unfortunately, almost always customer is wrong in this case.

So, if you cannot create an RPG program. Well, I can create a 'similar' RPG program and you can compare to your original to see if they match. ( This may be difficult as I don't know what style RPG your RPG guy is writing ... mmm ... tie both hands behind my back ... can you help me climb the RPG ladder sir??? )

kadler commented 6 years ago

Original comment by Brian Jerome (Bitbucket: bjerome, GitHub: brianmjerome).


I will get some help on that and report back.

kadler commented 6 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


Ok, are you creating said RPG program?

kadler commented 6 years ago

Original comment by Brian Jerome (Bitbucket: bjerome, GitHub: brianmjerome).


I think a better approach would be to create a simple RPG program that returns a JSON string in a DS -- that's basically what the RPG is doing. Not to make excuses or anything... I don't write the RPG (I'm a front end developer with JS) so I really can't say if it's correct.

kadler commented 6 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


The RPG has been running for years working properly in our production environment.

Of course. However, new part is how you (human) interpret what dim RPG data structures actually mean.

Unfortunately, we must speculate without data (no RPG) ... so .. here is a common human mistake. Based on dim 1 above this is likely your error, wherein nobody writes ds structure of dim(1) for REQPARMS ... this looks dead wrong (user error).

Aka, few people that actually understand true layout of RPG structures (compiler thinking). For instance, REQPARMS may actually be 999 records and you have only told toolkit 1. Perhaps JSONDATA may actually be 999 records and you have only told toolkit 100. You must account for ALL records just like an RPG compiler ... your mind may want only 100 or 1 record but the true size is 999 both. You can never 'wish' for fewer records, you must account for actual dim(999) size.

Again, you are making me guess ... without RPG to look at.

Why must i account for all records of a dim(999) structure in input json???

Because you are acting as the RPG client call compiler as a toolkit. Tha is, your RPG program is expecting REQPARMS or JSONDATA dim(999), so you must account for all records on input. Basically, if you miss any dim(999), the layout of the next/following parameter will be off by as many records you missed. Not to mention your RPG program will likely blow up if it happens to touch beyond the missing records data.

Again, you are making me guess ... without RPG to look at ... (i am trying to help you swim with both of my hands tied behind my back ... Dude!)

kadler commented 6 years ago

Original comment by Brian Jerome (Bitbucket: bjerome, GitHub: brianmjerome).


Unfortunately it's not up to me whether I can post it. The RPG has been running for years working properly in our production environment.

kadler commented 6 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


The RPG is not the issue.

You really must post the RPG. We can not rule "user error" without actually looking at the RPG. It is fairly easy to make a type declaration incorrect especially ds structures).

kadler commented 6 years ago

Original comment by Brian Jerome (Bitbucket: bjerome, GitHub: brianmjerome).


Sorry the last line was cut off when posting.

Input

#!json
{"pgm":[
  {"name":"GETJSONDATA",  "lib":"DB2JSON"},
  {"ds": [{"name":"REQPARMS", "dim":1, "by":"in"},
    {"s": [
      {"name":"TEST1", "type":"6p0", "value":1},
      {"name":"TEST2", "type":"12p0", "value":12345678}
    ]}
  ]},
  {"ds": [{"name":"JSONDATA", "dim":100, "by":"out", "dou":"JSONCOUNT"},
    {"s": [
      {"name":"JSONDATA", "type":"64000a"}
    ]}
  ]},
  {"s": {"name":"JSONCOUNT", "type":"10i0", "by":"out", "setlen":"JSONDATA"}},
  {"s": {"name":"RTRNCD", "type":"8a", "by":"out"}}
]}

I cannot post the RPG -- this is just an example, not the actual data. The RPG is not the issue.

kadler commented 6 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


Wait a minute ... your input json is not valid. Save time by trying to validate before we look anything more.

https://jsonlint.com/ - json validate

#!bash

Error: Parse error on line 56:
...y": "out"                }           }
---------------------^
Expecting ',', ']', got 'EOF'
kadler commented 6 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


You will have to post both ends of the test (include RPG as well).