Same named parameters as JSON keys will be changed to 'name'
Issue #8
resolved
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
Comments (4)
-
Account Deleted -
Account Deleted Ok, fixed.
- Yips SuperDriver - 1.1.1-sg4 - toolkit json parser fix keyword in value position (Halmela)
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)
-
reporter This seems to be working now, thanks for the quick fix.
-
reporter - changed status to resolved
FIXED
- Log in to comment
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).
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).