I have a json object inside a single array, that was an original file that I have deleted some fields, now i want to mutate one of the key values for each entry. Here is some example Json. I Want to loop through and split the meta_value at http://www.website/wp-content/uploads/
right now my code is returning every meta_value as undefined instead of splitting the value, I think it has to do with the loop changing the key value and trying to split it after.
Any help would be greatly appreciated
This is the code I have so far that generates the json data at the very end
var exclusions = [
"ID", "post_author", "post_date_gmt", "post_excerpt", "comment_status",
"ping_status", "post_password", "to_ping" ,"pinged", "post_modified","post_name",
"post_modified_gmt", "post_content_filtered", "guid", "menu_order", "post_mime_type",
"comment_count", "meta_id", "post_id", "post_type", "post_status"
];
var a = JSON.parse(fs.readFileSync('final.json'));
a.forEach(obj=>{
exclusions.forEach(excl=>{
if(obj[excl] || obj[excl] === ""){
delete obj[excl];
}
if(obj["meta_value"] !== undefined){
let objTest = obj["meta_value"].split('http://www.fsd.ca/wp-content/uploads/')[1];
obj["meta_value"] = objTest;
}
});
});
console.log(a);
Json after initial exclusions
[
{
post_date: '2012-02-16 23:37:22',
post_content: `Today we worked at literacy centres. We are writing our own Three Bears story. We are reading with Mrs.Kitson, writing in our life books, working in our printing books and working on making words on the iPads. We use the apps Pocket phonics, magnet board and Montessori crosswords. We went to the library. In the afternoon we went to the gym and watched a play by Quest Theatre. It was called <span style="text-decoration: underline;">For</span> <span style="text-decoration: underline;">Art's Sake.</span> They told us that we are all artists and that we should use our imagination. We did zumba. We danced to The chihuahua song. We went to the DPA room and played different tag games. Our hearts worked hard. We had a fun day!`,
post_title: 'Hometime',
meta_value: 'http://www.fsd
- List item
.ca/wp-content/uploads/2012/02/SN850631.jpg' }, { post_date: '2012-02-21 20:39:19', post_content: 'Today we started making our castles. We painted them colourful tissue paper. We are writing our own fairy tales. We read The Princess Frog Fairy Tale. We are making clay dragons and sewing puppets. We went to the gym and skipped. We wrote in our life books an practiced our printing. We had a fun day!', post_title: 'Creating Castles', meta_value: 'http://www.fd.ca/wp-content/uploads/2012/02/SN850649.jpg' }, { post_date: '2012-02-23 21:30:55', post_content: 'We talked about the letter E. E is a vowel. There is a vowel in every word. We did our E sheets. We went skating. We had hot chocolate after skating. We worked at new literacy centers. We are doing hard work. We went to Music. We played the bumble bee game. We went to the DPA room to play tag and dance. We went to centers and to the library. We had a fun day!', post_title: 'We Have New Pillows', meta_value: 'http://www.fds.ca/wp-content/uploads/2012/02/SN850660.jpg' }, { post_date: '2012-02-24 19:06:39', post_content: 'Today it was Hawaii Day. We wore shorts and summer clothes. We made a Chicka Chicka Boom Boom picture. We made leis. We ate batter dipped pineapples and ate mango, pineapple, papaya, starfruit, dragon fruit and coconut. We tried coconut water. We did the limbo and danced Hawaii style. We sat on our towels and played a math game where we guessed how many candies were under the cup. We wrote in our life books and we went to the big park. We had a fun, fun day!', post_title: 'Hawaii Day', meta_value: 'http://www.ff.ca/wp-content/uploads/2012/02/SN850665.jpg' }, ... 654 more items ]
Json after meta_value key value change, every value is undefined
[
{
post_date: '2012-02-16 23:37:22',
post_content: `Today we worked at literacy centres. We are writing our own Three Bears story. We are reading with Mrs.Kitson, writing in our life books, working in our printing books and working on making words on the iPads. We use the apps Pocket phonics, magnet board and Montessori crosswords. We went to the library. In the afternoon we went to the gym and watched a play by Quest Theatre. It was called <span style="text-decoration: underline;">For</span> <span style="text-decoration: underline;">Art's Sake.</span> They told us that we are all artists and that we should use our imagination. We did zumba. We danced to The chihuahua song. We went to the DPA room and played different tag games. Our hearts worked hard. We had a fun day!`,
post_title: 'Hometime',
meta_value: undefined
},
{
post_date: '2012-02-21 20:39:19',
post_content: 'Today we started making our castles. We painted them colourful tissue paper. We are writing our own fairy tales. We read The Princess Frog Fairy Tale. We are making clay dragons and sewing puppets. We went to the gym and skipped. We wrote in our life books an practiced our printing. We had a fun day!',
post_title: 'Creating Castles',
meta_value: undefined
},
{
post_date: '2012-02-23 21:30:55',
post_content: 'We talked about the letter E. E is a vowel. There is a vowel in every word. We did our E sheets. We went skating. We had hot chocolate after skating. We worked at new literacy centers. We are doing hard work. We went to Music. We played the bumble bee game. We went to the DPA room to play tag and dance. We went to centers and to the library. We had a fun day!',
post_title: 'We Have New Pillows',
meta_value: undefined
},
{
post_date: '2012-02-24 19:06:39',
post_content: 'Today it was Hawaii Day. We wore shorts and summer clothes. We made a Chicka Chicka Boom Boom picture. We made leis. We ate batter dipped pineapples and ate mango, pineapple, papaya, starfruit, dragon fruit and coconut. We tried coconut water. We did the limbo and danced Hawaii style. We sat on our towels and played a math game where we guessed how many candies were under the cup. We wrote in our life books and we went to the big park. We had a fun, fun day!',
post_title: 'Hawaii Day',
meta_value: undefined
},
... 654 more items
]