Skip to content
Advertisement

How to delete everything inside an object in a json file but keep the object?

I want to delete everything in the object “name” in the given json file example but keep the the object, in simple words I want to clear the object.

JavaScript

I used tried this code:

JavaScript

but it just clears the whole json file

sorry for my bad english

Advertisement

Answer

The problem is that you open the same file twice – for reading and for writing simultaneously. Also a JSON cannot be parsed line by line, only as a whole.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement