I am using ExpressJS to write my application and jsonfile (https://www.npmjs.com/package/jsonfile) to handle json files. I have this following json file:
{
"news": [
{
"id": "1",
"title": "News 1 heading",
"description": "Lorem ipsum dolor sit amet upidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"dateposted": "00188292929"
},
{
"id": "2",
"title": "News 2 heading",
"description": "Lorem ipsum dolor sit amet",
"dateposted": "00188292929"
}
]
}
Now, I want to add another set of news under the "news" node, so that my final json looks like this:
{
"news": [
{
"id": "1",
"title": "News 1 heading",
"description": "Lorem ipsum dolor sit amet upidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
"dateposted": "00188292929"
},
{
"id": "2",
"title": "News 2 heading",
"description": "Lorem ipsum dolor sit amet",
"dateposted": "00188292929"
},
{
"id": "3",
"title": "News 3 heading",
"description": "Lorem ipsum dolor sit amet",
"dateposted": "00188292929"
}
]
}
There is an append flag with jsonfile but it appends at the end of the file rather than under a given node. How can I append the data under and existing node? Do, I need to stringify the json, add data and JSONfy it? or there is a more direct way?
Thanks.