I have some JSON with structure like
{
"columns": [
{
"id": 123,
"title": "column 1"
},
{
"id": 456,
"title": "column 2"
}
],
"rows": [
{
"cells": [
{
"columnId": 123,
"value": "foo"
},
{
"columnId": 456,
"value": "bar"
}
]
},
{
"cells": [
{
"columnId": 123,
"value": "foo1"
},
{
"columnId": 456,
"value": "bar1"
}
]
}
Each row has a cell for every column and columnId matches id in columns.
How could I get a list of objects looking like:
[
{
'column 1': 'foo',
'column 2': 'bar'
},
{
'column 1': 'foo1',
'column 2': 'bar1'
}
2
Answers
This works, but it’s pretty messy
Here’s a way that uses
INDEX
andJOIN
to perform the matching, oneadd
to combine both sides of the match, and anotheradd
to create the final object (along with two other variants that each omit and compensate for anadd
).Demo
Demo
Demo
And here’s one that combines using
INDEX
with @Glenn’s shorter approach tomap
the.cells
array:Demo