I'm stuck with MySQL 5.7 and to reduce the amount of data retrieved I need to transform a JSON array within a SQL query.
My column is JSON and with a value structured like that:
{
"foo": [{
"bar" : "BAR1",
"baz" : "BAZ1",
"qux" : "QUX1"
}, {
"bar" : "BAR2",
"baz" : "BAZ2",
"qux" : "QUX2"
}]
}
I don't know how many items are in the array. I want the result to be structured like that:
{
"foo" : [
["BAR1", "BAZ1"],
["BAR2", "BAZ2"]
]
}
Basically I need to transform item objects to arrays (and skip qux
).
Unfortunately JSON_REMOVE
does not allow wildcard:
An error occurs if [...] any path argument is not a valid path expression or contains a * or ** wildcard.
Is it possible to pass JSON_SEARCH
results as JSON_ARRAY
or JSON_REMOVE
arguments?