test-fullautomation / python-jsonpreprocessor

A preprocessor for json files
Apache License 2.0
2 stars 2 forks source link

Improper parsing of composite data structure #349

Open HolQue opened 2 hours ago

HolQue commented 2 hours ago

JSON:

"param"  : 1,
"params" : [
              2,
              {"A" : 3,
               "B" : [
                        {
                           "C" : 4,
                           "D" : 5
                        },
                        6
                     ]
              },
              7
           ]

Result:

[DOTDICT] (2/1) > {param} [INT]  :  1
[DOTDICT] (2/2) > {params} [LIST] (3/1) > [INT]  :  2
[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/1) > {A} [INT]  :  3
[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [LIST] (2/1) > [DOTDICT] (2/1) > {C} [INT]  :  4
[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [LIST] (2/1) > [DOTDICT] (2/2) > {D} [INT]  :  5
[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [LIST] (2/2) > [INT]  :  6
[DOTDICT] (2/2) > {params} [LIST] (3/3) > [INT]  :  7

This result is like expected.

Now, between key "C" and "D", I add a line to change the initial value of key "C".

"param"  : 1,
"params" : [
              2,
              {"A" : 3,
               "B" : [
                        {
                           "C" : 4,
                           ${params}[1]['B'][0]['C'] : 10,
                           "D" : 5
                        },
                        6
                     ]
              },
              7
           ]

Result

[DOTDICT] (2/1) > {param} [INT]  :  1
[DOTDICT] (2/2) > {params} [LIST] (3/1) > [INT]  :  2
[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/1) > {A} [INT]  :  3
[DOTDICT] (2/2) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [INT]  :  6
[DOTDICT] (2/2) > {params} [LIST] (3/3) > [INT]  :  7

I am confused about this result. Key "B" has value 6 now and the entire dictionary with key "C" and "D" has disappeared.

Expected is the same data structure like in the first example, but with key "C" has value 10 instead of 4.

HolQue commented 1 hour ago

Same result if I omit the scope of "C" while changing the initial value:

"params" : [
              2,
              {"A" : 3,
               "B" : [
                        {
                           "C" : 4,
                           ${C} : 10,
                           "D" : 5
                        },
                        6
                     ]
              },
              7
           ]

Result:

[DOTDICT] (1/1) > {params} [LIST] (3/1) > [INT]  :  2
[DOTDICT] (1/1) > {params} [LIST] (3/2) > [DOTDICT] (2/1) > {A} [INT]  :  3
[DOTDICT] (1/1) > {params} [LIST] (3/2) > [DOTDICT] (2/2) > {B} [INT]  :  6
[DOTDICT] (1/1) > {params} [LIST] (3/3) > [INT]  :  7

Expected: Error message about a parameter (${C}) that does not exist at this position.

test-fullautomation commented 1 hour ago

hm... this we had already. Should give an error message...