How can I get this old array:
[
{
"_table": {
"_base": {
"_airtable": {},
"_id": "appDxGpKPJl3Exjs2"
},
"id": null,
"name": "PropMatters"
},
"id": "recGBOdnDtrvaEu7N",
"_rawJson": {
"id": "recGBOdnDtrvaEu7N",
"createdTime": "2022-05-24T07:05:22.000Z",
"fields": {
"Name": "Mon 23 May, Tues 24 May",
"KeyID": "2024f0d10106261cdc852194042d731c"
}
},
"fields": {
"Name": "Mon 23 May, Tues 24 May",
"KeyID": "2024f0d10106261cdc852194042d731c"
}
},
{
"_table": {
"_base": {
"_airtable": {},
"_id": "appDxGpKPJl3Exjs2"
},
"id": null,
"name": "PropMatters"
},
"id": "recS98niJqeUmlQ1n",
"_rawJson": {
"id": "recS98niJqeUmlQ1n",
"createdTime": "2022-05-24T07:59:22.000Z",
"fields": {
"Name": "Mediator Demo",
"KeyID": "eb0e79a50044cf02c1969e7f20093788"
}
},
"fields": {
"Name": "Mediator Demo",
"KeyID": "eb0e79a50044cf02c1969e7f20093788"
}
}
]
To output something like this:
[
{
"Name": "Mon 23 May, Tues 24 May",
"KeyID": "2024f0d10106261cdc852194042d731c"
},
{
"Name": "Mediator Demo",
"KeyID": "eb0e79a50044cf02c1969e7f20093788"
},
]
So as you can see, I’d like to output a new array simplifying the old JSON array to loop through each "fields" array item.
I have a feeling I’d use js maparray function, but I get lost if it’s more than a simple array.
>Solution :
The objects that you want in your array just correspond to the "fields" key in the "old" array. So you can just map the array:
const oldArray = JSON.parse(json);
const newArray = oldArray.map(entry => entry.fields);
And turn it back to JSON if needed.