javascript - How to remove unwanted keys and key values -



here original json object retrieving couchdb database:

 {   "total_rows": 3,   "offset": 0,   "rows": [     {       "id": "1e8fe199d4e761b71bb8920eb3003db2",       "key": null,       "value": {         "_id": "1e8fe199d4e761b71bb8920eb3003db2",         "_rev": "3-6979e0cd646f2bc0ddf84c0664d25808",         "room_number": 99,         "location": "city campus",         "timetable": {           "monday": [             "08:30",             "10:00",             "11:30",             "13:30",             "14:14"           ],           "tuesday": [             "08:30",             "10:00",             "11:30",             "13:30",             "14:14"           ],           "sunday": [            "08:30",             "10:00",             "11:30",             "13:30",             "14:14"           ]         }       }     },     {       "id": "1e8fe199d4e761b71bb8920eb3004cc6",       "key": null,       "value": {         "_id": "1e8fe199d4e761b71bb8920eb3004cc6",         "_rev": "2-f7250cca62a804137174a20f48312c40",         "room_number": 12,         "location": "city hall",         "timetable": {           "monday": [             "08:30",             "10:00",             "11:30",             "13:30",             "14:14"           ],           "tuesday": [             "08:30",             "10:00",             "11:30",             "13:30",             "14:14"           ],           "sunday": [            "08:30",             "10:00",             "11:30",             "13:30",             "14:14"           ]       }     }   ] } 

i want make json object below:

[     {         "room_number": 99,         "location": "city campus",         "timetable": {           "monday": [             "08:30",             "10:00",             "11:30",             "13:30",             "14:14"           ],           "tuesday": [             "08:30",             "10:00",             "11:30",             "13:30",             "14:14"           ],           "sunday": [            "08:30",             "10:00",             "11:30",             "13:30",             "14:14"           ]         }     },     {         "room_number": 12,         "location": "city hall",         "timetable": {           "monday": [             "08:30",             "10:00",             "11:30",             "13:30",             "14:14"           ],           "tuesday": [             "08:30",             "10:00",             "11:30",             "13:30",             "14:14"           ],           "sunday": [            "08:30",             "10:00",             "11:30",             "13:30",             "14:14"           ]         }     } ] 

here have got far:

[     {         "value": {             "room_number": 99,             "location": "city campus",             "timetable": {               "monday": [                 "08:30",                 "10:00",                 "11:30",                 "13:30",                 "14:14"               ],               "tuesday": [                 "08:30",                 "10:00",                 "11:30",                 "13:30",                 "14:14"               ],               "sunday": [                "08:30",                 "10:00",                 "11:30",                 "13:30",                 "14:14"               ]             }         }     },     {         "value": {             "room_number": 12,             "location": "city hall",             "timetable": {               "monday": [                 "08:30",                 "10:00",                 "11:30",                 "13:30",                 "14:14"               ],               "tuesday": [                 "08:30",                 "10:00",                 "11:30",                 "13:30",                 "14:14"               ],               "sunday": [                "08:30",                 "10:00",                 "11:30",                 "13:30",                 "14:14"               ]             }         }     } ] 

here nodejs code using achieve this:

var express = require('express')    , db = require('nano')('http://localhost:5984/rooms_database')    , app = express();  // query view db.view('show_rooms', 'view_show_rooms', function (err, doc) {     app.get("/", function(request,response)     {         var json_data = doc;         json_data = json_data.rows;          (var = 0; < json_data.length; i++)         {             delete json_data[i].id;             delete json_data[i].key;             delete json_data[i].value._id;             delete json_data[i].value._rev;         }          response.send(json_data);     }); });  app.listen(8080); console.log('************ server running! ************'); 

i using standard view in couchdb:

function(doc) {     emit(null, doc); } 

can tell me how rid of 'value' key in json object?

you can this

var json_data = doc; json_data = json_data.rows; var output=[];  (var = 0; < json_data.length; i++) {     var temp = json_data[i].value;     delete temp._id;     delete temp._rev;     output.push(temp); }  response.send(output); 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

php - Dynamic url re-writing using htaccess -

java - Multi-Label Document Classification -