I am trying to take JSON data information from a separate file and insert that info into a newly created object. I know there are a lot of similar questions, but how do you do this with Node JS? I've tried just about all the options from the following link with no success
Add new element to an existing object
Ex:
"EXTERNAL-DATA" : [
{
"clients" {
{
"firstName" : "Thomas",
"lastName" : "Johnson",
"profession" : "Carpenter",
"age": 27,
"education": {
"Diploma": true
}
},
{
"firstName" : "Jane",
"lastName" : "Simpson",
"profession" : "Teacher",
"age": 32,
"education": {
"Masters Degree": true,
"College Degree": true,
"Diploma": true
}
}
}
}
]
If I only want to capture, say firstName, lastName, and education and place each client in a new, empty object collectedData as their own individual objects, how would I go about doing that?
Assuming the EXTERNAL DATA is held inside a variable called data
- I've tried the spread operator
collectedData = {... collectedData[i], ...data[i]}, but it doesn't add each as new objects - I've tried using
new Object();each time I loop through, but I'm not sure how the left-hand side is supposed to look when there are thousands of objects from the external JSON file. - I've tried
Object.assign(), but with no luck
I know I'm overthinking it, but does anybody have an idea even for what direction to go in? I feel burned out.
Would eventually look like this:
collectedData = {
{
"firstName": "Thomas",
"lastName": "Johnson",
"education": {
"Diploma": true
}
},
{
"firstName": "Jane",
"lastName": "Simpson",
"education": {
"Masters Degree": true,
"College Degree": true,
"Diploma": true
}
}
}