I have a json like this:
{
"result": [
{
"timestamp": 1234567890,
"textsList": [
{
"text": "some text here 0"
}
],
"otherList": [
{
"type": "Nothing"
},
{
"type": "Recursive",
"data": {
"timestamp": 12345678901234,
"textsList": [
{
"text": "some other text 1"
}
],
"otherList": [
{
"type": "Nothing"
},
{
"type": "Recursive",
"data": {
"timestamp": 12345678901234,
"textsList": [
{
"text": "some other text 2"
}
],
"otherList": []
}
}
]
}
}
]
}
]
}
I'm trying to extract a new json like this one:
[{
"timestamp": 1234567890,
"text": "some text here 0"
},
{
"timestamp": 12345678901234,
"text": "some other text 1"
},
{
"timestamp": 1234567890,
"text": "some other text 2"
}
]
since otherList can be infinite, I'm trying to use a recursive function. unfortunately, It seems that I don't understand something. This is my basic function to get data:
def getText (element):
textData = {
"timestamp": element["timestamp"],
"text": element["textList"][0]["text"],
}
return textData
then in main.py I call a for to pass over each result, I put timestamp and text in a list like:
for el in jsonFile:
textData = getText(jsonresult)
and after that I should run the recursive for all the elements in otherList but I don't understand how.