Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion JsonPreprocessor/CJsonPreprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

from PythonExtensionsCollection.String.CString import CString
from enum import Enum
from JsonPreprocessor.version import VERSION, VERSION_DATE

class CSyntaxType():
python = "python"
Expand Down Expand Up @@ -173,6 +174,12 @@ class CJsonPreprocessor():
- Allow Python data types ``True``, ``False`` and ``None``
"""

def getVersion(self):
return VERSION

def getVersionDate(self):
return VERSION_DATE

def __init__(self, syntax: CSyntaxType = CSyntaxType.python , currentCfg : dict = {}) -> None:
"""
Constructor
Expand Down Expand Up @@ -958,7 +965,7 @@ def __recursiveNestedHandling(sInputStr: str, lNestedParam: list) -> str:
self.lNestedParams.append(nestedParam)
newInputStr = newInputStr + item if tmpItem==items[len(items)-1] else newInputStr + item + ","
sInputStr = newInputStr
elif re.search("\${\s*}", sInputStr) or re.search("\${.+}\.", sInputStr) \
elif re.search("\${\s*}", sInputStr) \
or (nestedKey and (sInputStr.count("{") != sInputStr.count("}") or sInputStr.count("[") != sInputStr.count("]"))):
self.__reset(bCleanGlobalVars=True)
raise Exception(f"Invalid parameter format: {sInputStr}")
Expand Down
Binary file modified JsonPreprocessor/JsonPreprocessor.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions JsonPreprocessor/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
#
# Version and date of JsonPreprocessor
#
VERSION = "0.3.2"
VERSION_DATE = "17.01.2024"
VERSION = "0.3.3"
VERSION_DATE = "23.01.2024"

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
json_preprocessor = CJsonPreprocessor()
json_preprocessor.jsonDump(dictTest, \"./OutputFile.json\")

* Added ``getVersion`` and ``getVersionDate`` methods to get current version and the date of the version.
* Improved format of nested parameters; improved error messages
* Some bugs fixed in implicitly created data structures
* Improved index handling together with nested parameters
Expand Down
5 changes: 3 additions & 2 deletions packagedoc/additional_docs/History.tex
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
- Fix bugs of data structures implicitly\newline
- Improve index handling together with nested parameters}

\historyversiondate{0.3.2}{01/2024}
\historyversiondate{0.3.3}{01/2024}
\historychange{- Some bugs fixed in implicitly created data structures\newline
- Improved index handling together with nested parameters\newline
- Improved format of nested parameters; improved error messages}
- Improved format of nested parameters; improved error messages\newline
- Added getVersion and getVersionDate methods to get current version and the date of the version}

\end{packagehistory}
70 changes: 70 additions & 0 deletions packagedoc/additional_docs/The JSONP format.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1191,5 +1191,75 @@ \section{Implicite creation of dictionaries}
{'paramA': 'ABC', 'subKey': 'ABC', 'testdict': {'subKey': {'subKey': {'paramA': 'DEF'}}}}
\end{pythonlog}

\vspace{2ex}

\textbf{Reference to existing keys}

It is possible to use parameters to refer to \textit{already existing} keys.

\begin{pythoncode}
{
// <data structure created implicitly>
${testdict.subKey_1.subKey_2.subKey_3} : "ABC",

// <string parameter with name of an existing key>
"keyName_3" : "subKey_3",

// <parameter used to refer to an existing key>
${testdict.subKey_1.subKey_2.${keyName_3}} : "XYZ"
}
\end{pythoncode}

\vspace{2ex}

\textbf{Outcome:}

\begin{pythonlog}
{'keyName_3': 'subKey_3',
'testdict': {'subKey_1': {'subKey_2': {'subKey_3': 'XYZ'}}}}
\end{pythonlog}

\vspace{2ex}

Parameters cannot be used to create new keys.

\begin{pythoncode}
{
// <data structure created implicitly>
${testdict.subKey_1.subKey_2.subKey_3} : "ABC",

// <string parameter with name of a not existing key>
"keyName_4" : "subKey_4",

// <usage of keyName\_4 is not possible here>
${testdict.subKey_1.subKey_2.subKey_3.${keyName_4}} : "XYZ"
}
\end{pythoncode}

\vspace{2ex}

\textbf{Outcome is the following error:}

\begin{pythonlog}
"The implicit creation of data structures based on nested parameter is not supported ..."
\end{pythonlog}

The same error will happen in case of the standard notation is used:

\begin{pythoncode}
{
// <usage of keyName\_4 is not possible here>
${testdict}['subKey_1']['subKey_2']['subKey_3'][${keyName_4}] : "XYZ"
}
\end{pythoncode}









% --------------------------------------------------------------------------------------------------------------

9 changes: 5 additions & 4 deletions test/testfiles/jpp-test_config_1002.jsonp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
"paramD" : "D",
"paramE" : "E",
${testdict_3.paramD.paramE.paramD} : {"E" : 5},
${testdict_3.paramD.paramE.paramD}[${paramE}] : {"F" : 6} // if not implicit, usage of parameters for key names is allowed
//
// needs to be clarified (currently throws an implicit creation error)
// ${testdict_4} : {},
// ${testdict_4}[${paramD}] : {"G" : 7}
// usage of parameters allowed only in case of a key with this name already exists



${testdict_3.paramD.paramE.paramD}[${paramE}] : {"F" : 6} // ${paramE} is accepted because the value is "E" and a key with this name already exists
}

2 changes: 1 addition & 1 deletion test/testfiles/jpp-test_config_1051.jsonp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

{
"testdict" : {"A" : 1},
"name" : "C",
"name" : "C",
${testdict.B.${name}} : 2
}

2 changes: 1 addition & 1 deletion test/testfiles/jpp-test_config_1052.jsonp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

{
"testdict" : {"A" : 1},
"name" : "C",
"name" : "C",
${testdict}['${name}']['${name}'] : 2
}

2 changes: 1 addition & 1 deletion test/testfiles/jpp-test_config_1053.jsonp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//**************************************************************************

{
"name" : "C",
"name" : "C",
"testdict2" : {"B" : 2},
${somethingnotexisting.${testdict2}}['${name}'] : 4
}
Expand Down
2 changes: 1 addition & 1 deletion test/testfiles/jpp-test_config_1054.jsonp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//**************************************************************************

{
"name" : "C",
"name" : "C",
"testdict" : {"B" : 2},
${testdict.${testdict}}['${name}'] : 4
}
Expand Down
2 changes: 1 addition & 1 deletion test/testfiles/jpp-test_config_1055.jsonp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//**************************************************************************

{
"name" : "C",
"name" : "C",
"testlist" : ["B", 2],
${testlist.${testlist}}['${name}'] : 4
}
Expand Down
2 changes: 1 addition & 1 deletion test/testfiles/jpp-test_config_1056.jsonp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

{
"testdict" : {"A" : 1},
"name" : "C",
"name" : "C",
${testdict.${name}}['${name}'] : 5
}

2 changes: 1 addition & 1 deletion test/testfiles/jpp-test_config_1057.jsonp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

{
"testdict" : {"A" : 1},
"name" : "C",
"name" : "C",
${testdict}[${name}][${name}] : 4
}

1 change: 1 addition & 0 deletions test/testfiles/jpp-test_config_1058.jsonp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//**************************************************************************

{
"testdict" : {"A" : 1},
"name" : "C",
Expand Down