node-jsonfile icon indicating copy to clipboard operation
node-jsonfile copied to clipboard

does it support append file?

Open sssahas opened this issue 9 years ago • 7 comments

is there a way to do append new objects to a file?

sssahas avatar Jun 13 '16 00:06 sssahas

I have the same question. Its working well for me but it overwrites the existing json rather than adding to it

ajsingh007 avatar Jun 24 '16 02:06 ajsingh007

Same here... this would be a perfect little json to file utility if it included jsonfile.appendFile() and jsonfile.appendFileSync() functionality too.

dudleyjosh avatar Jun 27 '16 19:06 dudleyjosh

:+1: without this I cant use it.

SCBuergel avatar Aug 02 '16 18:08 SCBuergel

please support append file

kamikazechaser avatar Aug 13 '16 12:08 kamikazechaser

See my comments here, I think it's related.

I had a similar issue, wanted to to hack our package.json file to update the browser key depending on the environment, and this approach worked okay.

TL;DR - read the file in the object, update the update, and write the object back to the file afresh.

andela-anandaa avatar Mar 20 '17 13:03 andela-anandaa

As discussed in https://github.com/jprichardson/node-jsonfile/issues/67, you can use Object.assign to accomplish something like this. You can't truly append to a JSON file in the filesystem sense, so I don't see the point of adding this syntax sugar to jsonfile.

@jprichardson what are your thoughts here?

RyanZim avatar Apr 25 '17 14:04 RyanZim

@jprichardson what are your thoughts here?

Agreed. I'd prefer to rework (move to its own section) the README a bit to make it very clear and distinct on the two cases of appending or updating.

jprichardson avatar Apr 25 '17 16:04 jprichardson