I'm currently trying to extract data from a JSON line, and store the data in an array. The data is a mathematical equation and has operators, groups and values
{
"rightArgument": {
"cell": "C6",
"value": 13394.5,
"type": "cell"
},
"leftArgument": {
"rightArgument": {
"value": "20",
"type": "constant"
},
"leftArgument": {
"rightArgument": {
"value": "90",
"type": "constant"
},
"leftArgument": {
"value": "100",
"type": "constant"
},
"type": "operation",
"operator": "+"
},
"type": "operation",
"operator": "+"
},
"type": "operation",
"operator": "+"
}
I'm able to extract the first operator and value (+ and 13394.5) however when attempting to navigate down the structure I'm thrown with many errors. I was wondering if anyone could help describe or assist with my code on how to do this?
Currently I have this Python code:
def _getCurrentOperator(data): # function to find current scope operator, pass in the current scope ie data, rightargument, leftargument
list.append(data["operator"])
data = data["rightArgument"]
list.append(data["value"])
data = data["leftArgument"]
_getCurrentOperator(data)
edit:
Within some of my mathematical formulae I have to cater for brackets, which are shown by type: "group" in my JSON file: here is an example of the JSON file:
{
"rightArgument": {
"rightArgument": {
"value": "2",
"type": "constant"
},
"leftArgument": {
"value": "90",
"type": "constant"
},
"type": "operation",
"operator": "/"
},
"leftArgument": {
"rightArgument": {
"arguments": [],
"name": "pi",
"type": "function"
},
"leftArgument": {
"rightArgument": {
"argument": {
"rightArgument": {
"value": "100",
"type": "constant"
},
"leftArgument": {
"rightArgument": {
"cell": "C7",
"value": 13604.5,
"type": "cell"
},
"leftArgument": {
"rightArgument": {
"value": "20",
"type": "constant"
},
"leftArgument": {
"value": "90",
"type": "constant"
},
"type": "operation",
"operator": "/"
},
"type": "operation",
"operator": "*"
},
"type": "operation",
"operator": "+"
},
"type": "group"
},
"leftArgument": {
"value": "100",
"type": "constant"
},
"type": "operation",
"operator": "+"
},
"type": "operation",
"operator": "+"
},
"type": "operation",
"operator
": "+"
}