Skip to content
16 changes: 5 additions & 11 deletions JsonPreprocessor/CJsonPreprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def __init__(self, syntax: CSyntaxType = CSyntaxType.python , currentCfg : dict
self.jsonCheck = {}
self.JPGlobals = {}
self.pythonTypeError = ["object is not subscriptable", \
"string indices must be integers"]
"string indices must be integers", \
"list indices must be integers"]

def __getFailedJsonDoc(self, jsonDecodeError=None, areaBeforePosition=50, areaAfterPosition=20, oneLine=True):
failedJsonDoc = None
Expand Down Expand Up @@ -514,7 +515,8 @@ def __getNestedValue(sNestedParam : str):
if errorType in str(error):
errorMsg = f"Could not resolve expression '{sNestedParam.replace('$$', '$')}'."
if errorMsg != '':
errorMsg = errorMsg + f" Reason: {error}"
errorMsg = errorMsg + f" Reason: {error}" if ' or slices' not in str(error) else \
errorMsg + f" Reason: {str(error).replace(' or slices', '')}"
else:
errorMsg = f"The parameter '{sNestedParam.replace('$$', '$')}' is not available!"
raise Exception(errorMsg)
Expand Down Expand Up @@ -629,15 +631,7 @@ def __handleDotInNestedParam(sNestedParam : str) -> str:
rootVar = re.search(pattern, var[0], re.UNICODE)[0]
sRootVar = __handleDotInNestedParam(rootVar) if "." in rootVar else rootVar
sVar = var[0].replace(rootVar, sRootVar)
if re.search(r"\[\s*'[\s\-]*\d+\s*'\s*\]", sVar):
try:
tmpValue = __getNestedValue(sVar)
except:
errorMsg = f"{rootVar.replace('$$', '$')} expects integer as index. Got string instead in {sNestedParam}"
self.__reset()
raise Exception(errorMsg)
else:
tmpValue = __getNestedValue(sVar)
tmpValue = __getNestedValue(sVar)
if bConvertToStr and (isinstance(tmpValue, list) or isinstance(tmpValue, dict)):
dataType = re.sub(r"^.+'([a-zA-Z]+)'.*$", "\\1", str(type(tmpValue)))
self.__reset()
Expand Down
Binary file modified JsonPreprocessor/JsonPreprocessor.pdf
Binary file not shown.
18 changes: 13 additions & 5 deletions packagedoc/additional_docs/The JSONP format.tex
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ \section{Overwrite parameters}\label{overwrite-parameters}

\vspace{2ex}

Using composite data types inside strings causes errors:
Using composite data types inside strings is not supported:

\begin{pythoncode}
"newparam6" : "prefix_${listval}_suffix"
Expand All @@ -615,10 +615,18 @@ \section{Overwrite parameters}\label{overwrite-parameters}
"newparam7" : "prefix_${dictval}_suffix"
\end{pythoncode}

\textbf{TODO:} \href{https://github.com/test-fullautomation/python-jsonpreprocessor/issues/249}{Parameter substitution needs to be limited}
\vspace{2ex}

Result for \pcode{"newparam6"}:

\vspace{2ex}

\begin{pythonlog}
The substitution of parameter '${listval}' inside the string value 'prefix_${listval}_suffix' is not supported! Composite data types like lists and dictionaries cannot be substituted inside strings.
\end{pythonlog}

\newpage

\textbf{Value of a single element of a parameter of nested data type}

To access an element of a list and a key of a dictionary, we change the content of file \plog{componentB.2.jsonp} to:
Expand Down Expand Up @@ -998,7 +1006,7 @@ \section{Dynamic key names}
\end{pythoncode}

The value of \pcode{newparam1} is defined by an expression that is encapsulated in quotes and contains - beneath hard coded parts - a dollar operator expression
that is the dynamic part.
(that is the dynamic part).

The same is also possible on the left hand side of the colon. In this case the name of a parameter is created dynamically.

Expand Down Expand Up @@ -1040,7 +1048,7 @@ \section{Dynamic key names}

\vspace{2ex}

This will not work:
This will not work (because of a key with name \pcode{A_2} does not yet exist):

\vspace{2ex}

Expand All @@ -1054,7 +1062,7 @@ \section{Dynamic key names}
\textbf{Outcome:}

\begin{pythonlog}
<TODO: error message>
A substitution in key names is not allowed! Please update the key name "${strval}_2"
\end{pythonlog}


Expand Down