node.js - How to delete a info with ID from JSON based data -


the content of json file is: retails.json file.actually retails database.i converted json file sql database.so in json file, want delete person information single id.how can do? using node.js , express.

{ "categories" : [ { "dept_id" : "123", "category_name" : "database", "category_discription" : "list of database", "current time" : "2016-07-21 06:27:17", "id" : "1" }, { "dept_id" : "1234", "category_name" : "debugging", "category_discription" : "program debugger", "current time" : "2016-07-21 06:32:24", "id": "2" }, { "dept_id" : "12345", "category_name" : "system analyzer", "category_discription" : null, "current time" : "2016-07-21 06:33:23", "id" : "3" } ], "departments" : [ { "name" : "manpreet singh", "address_info" : "qadian", "current time" : null, "id" : "1" }, { "name" : "tushal gupta", "address_info" : "amritsar", "current time" : "2016-07-21 06:10:14", "id" : "2" }, { "name" : "haroop singh", "address_info" : "amritsar", "current time" : "2016-07-21 06:11:12", "id" : "3" } ],  "digital_marketing" : [ { "dept_id" : "123", "phone" : "99889988", "mobile" : null, "email" : "thbs@gmail.com", "web" : null, "facebook" : null, "twitter" : null, "linkedin" : null, "current time" : "2016-07-21 06:10:16", "id" : "1" }, { "dept_id" : "1234", "phone" : "998899888", "mobile" : null, "email" : null, "web" : null, "facebook" : "gtudgal@fb.com", "twitter" : "tushalgupta", "linkedin" : null, "current time" : "2016-07-21 06:30:19", "id" : "2" }, { "dept_id" : "12345", "phone" : "99889877", "mobile" : null, "email" : "fhdts@mail.com", "web" : null, "facebook":"sdfh33@fb.com", "twitter" : null, "linkedin" : null, "current time" : "2016-07-21 06:30:13", "id" : "3"   }  ] } 

i using delete id, not work:

var id = 2; app.get('/deleteuser', function (req, res) {    // first read existing users.   fs.readfile( __dirname + "/" + "retails.json", 'utf8', function (err, data) {        data = json.parse( data );        delete data["categories" + 2];             console.log( data );      res.end( json.stringify(data));    }); }); 

for (var prop in jsonobj.categories){    delete jsonobj.categories[prop].id; } 

similar digital_marketing etc. jsonobj data in case..


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -