kadler / db2sock-test

1 stars 0 forks source link

Same named parameters as JSON keys will be changed to 'name' #8

Closed kadler closed 6 years ago

kadler commented 6 years ago

Original report by Teemu Halmela (Bitbucket: teemu_, GitHub: Unknown).


I found some weird behavior during my testing.

If I have a json which has parameters that are named same as some JSON parsing values, the parameter name is changed to 'name' in the output json.

This is easily tested with the example hello program by changing the parameter name.

input(108):
{"pgm":[{"name":"HELLO",  "lib":"DB2JSON"},
    {"s":{"name":"type", "type":"128a", "value":"Hi there"}}
]}

output(63): {"script":[{"pgm":["HELLO","DB2JSON",{"name":"Hello World"}]}]}

input(109):
{"pgm":[{"name":"HELLO",  "lib":"DB2JSON"},
    {"s":{"name":"typea", "type":"128a", "value":"Hi there"}}
]}

output(64): {"script":[{"pgm":["HELLO","DB2JSON",{"typea":"Hello World"}]}]}

These seem to be the offending keys https://bitbucket.org/litmis/db2sock/src/aaa30597c6fcc85f39852f22858af674cdd121f7/toolkit/parser-json/PaseJson.c?at=master&fileviewer=file-view-default#PaseJson.c-74

kadler commented 6 years ago

Original comment by Teemu Halmela (Bitbucket: teemu_, GitHub: Unknown).


FIXED

kadler commented 6 years ago

Original comment by Teemu Halmela (Bitbucket: teemu_, GitHub: Unknown).


This seems to be working now, thanks for the quick fix.

kadler commented 6 years ago

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


Ok, fixed.

#!bash

bash-4.3$ ./test1000_sql400json32 ../json/j0102_srvpgm_hello_evil_abuse_by_keyword
input(5000000):
{"pgm":[{"name":"HELLOSRV", "lib":"DB2JSON", "func":"HELLO"},
        {"s":{"name":"type", "type":"128a", "value":"Hi there"}}
       ]}

output(74):
{"script":[{"pgm":["HELLOSRV","DB2JSON","HELLO",{"type":"Hello World"}]}]}

result:
success (0)
kadler commented 6 years ago

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


json key words

Yes. These are reserved key words in the default json parser. In fact, always shall be reserved words for elements/attributes in any json parser ("pgm", "cmd", "type", etc.). However, I suspect when a elements/attributes key word appears in value position should be ignored. Appears to be a bug in parser-json module (libjson400.a).

#!json

{"s":{"name":"type", "type":"128a", "value":"Hi there"}}
-> name = "type" should be understood as "value" (not keyword)

{"s":{"name":"typea", "type":"128a", "value":"Hi there"}}
-> name = "typea" is in fact understood as "value" (not keyword)

DIY parsers (cheap db2sock advertisements) ...

For the record, you may replace json default parser (libjson400.a) with any other parser you choose. The only parser trick is map whatever keyword you choose to actual toolkit ordinals/defines (libjson400.a->libtkit400.a). The toolkit calls back (callback), to allow you to format the output as your parser desire. In fact, we could build many different parsers that worked for XML, json, csv, bobs-custom-scripting, and they all would work with the toolkit proper (libbob->libtkit400.a).