Skip to content
Merged
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
21 changes: 12 additions & 9 deletions JsonPreprocessor/CJsonPreprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,15 +684,18 @@ def __handleStrNoneTrueFalse(objJson):
i=0
for item in items:
i+=1
subItems = re.split("\s*,\s*", item)
newSubItem = ""
j=0
for subItem in subItems:
j+=1
if j<len(subItems):
newSubItem = newSubItem + self.__checkAndUpdateKeyValue(subItem) + ", "
else:
newSubItem = newSubItem + self.__checkAndUpdateKeyValue(subItem)
if re.search("\s*\[[^\[\]]*\]\s*,*\s*", item):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Son,
can you explain me the code a little.
I would expect that inside a string (means between double quotes) data must be only processed if a ${ sequence exists. Otherwise it mustn't be touched.
Thank you,
Thomas

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Thomas,

This code I handle for the situation that a value (right hand side of ":" in Json config file) is a list and this list contains nested parameters. For example, "key" : [1, "two", ${nested}['abc']['def'], 3, "four"] then the value of nested param will be replaced in this list.

I think I forgot the case that a list value could be separated into multiple lines.

I will update my change tomorrow.

Thank you,
Son

subItems = re.split("\s*,\s*", item)
j=0
for subItem in subItems:
j+=1
if j<len(subItems):
newSubItem = newSubItem + self.__checkAndUpdateKeyValue(subItem) + ","
else:
newSubItem = newSubItem + self.__checkAndUpdateKeyValue(subItem)
else:
newSubItem = item
if i<len(items):
newLine = newLine + newSubItem + " : "
else:
Expand Down Expand Up @@ -720,7 +723,7 @@ def __handleStrNoneTrueFalse(objJson):

try:
oJson = json.loads(sJsonDataUpdated,
cls=CJSONDecoder ,
cls=CJSONDecoder,
object_pairs_hook=self.__processImportFiles)
except Exception as error:
raise Exception(f"json file '{jFile}': '{error}'")
Expand Down