test-fullautomation / python-jsonpreprocessor

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

Leading zeros in decimal integer #350

Open HolQue opened 1 month ago

HolQue commented 1 month ago

Implicit creation of a nested dictionary:

${params.001.param} : 2

Result:

Error: 'Could not set parameter '${params.001.param}' with value '2'! Reason: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers (<string>, line 1)'!

How to handle this?

In this combination it works properly:

"params" : {"001" : {"param" : 1}},
${params.001.param} : 2

Also this works properly:

${params}['001']['param'] : 1

Also no problems with:

${params.1.param} : 1

and with:

${params.a001.param} : 2

In Python 3, dictionary keys can also be of type int. But as per my understanding, JSON does not support numeric keys. Every key is of type str. How does the JsonPreprocessor handle expressions like:

${params.1.param} : 1

Is the key 1 of type int or of type str? If str, leading zeros should not harm the computation. And I have currently no idea why the JsonPreprocessor should make 1 an integer.

HolQue commented 1 month ago

Similar scenario:

"dictParam" : {"A" : 1, "B" : 2},
"param"     : ${dictParam.3}

A key error is detected properly:

Error: 'Could not resolve expression '${dictParam}[3]'. Reason: Key error 3'!

The same with leading zero in key name:

"dictParam" : {"A" : 1, "B" : 2},
"param"     : ${dictParam.03}

Result:

Error: 'The parameter '${dictParam}[03]' is not available!'!

For sure, that is not wrong, but I would prefer a 'key error'.