Suppose I have a table with some columns. One of the columns is called Details
, has a dynamic
type, and is an array of JSON objects similar to this:
[
{
"key": "Name",
"value": "Dave"
},
{
"key": "Age",
"value": "30"
},
{
"key": "Gender",
"value": "Male"
}
]
I would like to efficiently pull out the value
from the object that has the key
= Gender
, and store that in a new field called Gender
. However – an object with that key won’t always be in the field, and if that is the case I want to default it to Undefined
in my extracted property.
So if I had:
datatable(d:dynamic)
[
dynamic({
"Details":[
{"value":"Dave","key":"Name"},
{"value":"Male","key":"Gender"},
{"value":"30","key":"Age"}
]
}),
dynamic({
"Details":[
{"value":"Dan","key":"Name"},
{"value":"40","key":"Age"}
]
}),
]
I would want my two rows to be:
Gender
------
Male
Undefined
The dataset that will be queried will go back up to a year and could contain a million of rows, so that may affect the approach.
I am aware of mv-extend
and mv-apply
, but I don’t think these will work because the entire contents of the array needs to be considered when deciding whether to assign a default value or not.
Thank you 🙂