I'm currently facing an issue with extracting a value from a JSON object. Each JSON object in my array has a name (attribute), a similarity (ignore this for now), and an array named "values" with keys and corresponding values.
For each case, I have a value from this array, as shown in the example below. My goal is to retrieve the value from "Values" using the key specified in my case.
Currently, I am using two nested loops, one to find the correct attribute and another to find the right key. Is there a more efficient way to achieve this? If necessary, I can restructure this JSON schema.
Here is my array:
[
{
"attribute": "date",
"similarity": "Sim",
"values": [
{"key": "Unknown", "value": "?"},
{"key": "April", "value": "0"},
{"key": "May", "value": "1"},
{"key": "June", "value": "2"},
{"key": "July", "value": "3"},
{"key": "August", "value": "4"},
{"key": "September", "value": "5"},
{"key": "October", "value": "6"}
]
},
...
]
A sample case:
{
"case": 1,
"disease": "diaporthe-stem-canker",
"areaDamaged": "low-areas",
"cankerLesion": "Brown",
...
}
In the case where "areaDamaged" is set to "low-areas," I want to extract the corresponding value associated with "low-areas." Does anyone know a better approach?