CouchDBデータベースから取得する
元のJSONオブジェクトは次のとおりです。
{
"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"
]
}
}
]
}
以下の JSON オブジェクトのようにしたいと思います。
[
{
"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"
]
}
}
]
これが私がこれまでに得たものです:
[
{
"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"
]
}
}
}
]
これを実現するために使用しているNodeJSコードを次に示します。
var express = require('express')
, db = require('nano')('http://localhost:5984/rooms_database')
, app = express();
// query a 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;
for (var i = 0; i < 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 is running! ************');
CouchDBで標準ビューを使用しています:
function(doc)
{
emit(null, doc);
}
'value'
JSON オブジェクトのキーを削除する方法を誰か教えてもらえますか?