I have a dict like this
{
"library": [
{
"_type": "Host",
"parameters": "JSON STRING",
"superclassOf": [
{
"_type": "LinuxHost",
"superclassOf": [
{
"_type": "Ubuntu",
"superclassOf": [
{
"_type": "Ubuntu1604",
"parameters": "JSON STRING"
}
]
}
]
}
]
}
]
}
Where JSON STRING
is a dict in a string form (e.g. '{"property1":"value1","property2":"value2"}'
).
What I am looking for is a way to navigate recoursively the supeclassOf
property and convert these Json strings to real parts of json, and return the full dict once edited.
EDIT: note that supeclassOf
's values are lists. So everywhere there's a superclassOf
there can be multiple elements, each having (or not) properties parameters
and superclassOf
EDIT2 using Prem Anand's answer I get this error:
Traceback (most recent call last):
File "C:/Users/ceccolig/PycharmProjects/api/api.py", line 61, in <module>
main()
File "C:/Users/ceccolig/PycharmProjects/api/api.py", line 52, in main
process_list_or_dict(library)
File "C:/Users/ceccolig/PycharmProjects/api/api.py", line 45, in process_list_or_dict
process_list_or_dict(v)
File "C:/Users/ceccolig/PycharmProjects/api/api.py", line 45, in process_list_or_dict
process_list_or_dict(v)
File "C:/Users/ceccolig/PycharmProjects/api/api.py", line 45, in process_list_or_dict
process_list_or_dict(v)
[Previous line repeated 5 more times]
File "C:/Users/ceccolig/PycharmProjects/api/api.py", line 43, in process_list_or_dict
ld[k] = process_str(v)
File "C:/Users/ceccolig/PycharmProjects/api/api.py", line 37, in process_str
return json.loads(s)
File "C:\Users\ceccolig\AppData\Local\Programs\Python\Python38-32\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Users\ceccolig\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\ceccolig\AppData\Local\Programs\Python\Python38-32\lib\json\decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)