javascript - Lower casing the keys in JSON - Node JS -
i want change json array keys names upper case letters lower case keys following
[ { "_id": "581f2749fb9b6f22308f5063", "workshopid": "1", "workshoptitle": "workshop1", "workshopprice": "200", "workshopdescription": "workshop1 test workshop", "floornumber": "1", "roomnumber": "205", "workshoplanguage": "english language", "lastonlineregistrationdate": "15/10/2016", "workshopdate": "1/11/2016", "workshopstarttime": "8:00 am", "workshopendtime": "11:00 am", "workshoprules": "rules mentioned here", "workshopcapacity": "200", "speaker": { "speakername": "john doe", "aboutspeaker": "about speaker" } }, { "_id": "581f27e796915434f44cd678", "workshopid": "2", "workshoptitle": "workshop2", "workshopprice": "200", "workshopdescription": "workshop2 test workshop", "floornumber": "1", "roomnumber": "205", "workshoplanguage": "english language", "lastonlineregistrationdate": "15/10/2016", "workshopdate": "1/11/2016", "workshopstarttime": "11:00 am", "workshopendtime": "02:00 pm", "workshoprules": "rules mentioned here", "workshopcapacity": "200", "speaker": { "speakername": "jane doe", "aboutspeaker": "jane doe - speaker" } } ]
for example workshopid must changed workshopid, have function in node js query collection in mongodb , return json :
getworkshops: function (db, response) { db.collection('workshops').find().toarray(function (err, results) { var convertedarr = []; //convert json. response.send(json.stringify(convertedarr)); });
any help?
this map object's keys lowercase:
var uppercased = [ { id: 1, name: 'fred' }, { id: 2, name: 'sarah' }, { id: 3, name: 'joe' }, ]; var lowercased = uppercased.map(function(item) { var mapped = {}; (var key in item) { mapped[key.tolowercase()] = item[key]; } return mapped; });
Comments
Post a Comment