Error about 'invalid JSON' with couchDB view but the json's fine...
Posted
by Chris Huang-Leaver
on Stack Overflow
See other posts from Stack Overflow
or by Chris Huang-Leaver
Published on 2010-03-17T11:30:47Z
Indexed on
2010/03/17
11:31 UTC
Read the original article
Hit count: 645
I am trying to setup the following view on CouchDB
{
"_id":"_design/id",
"_rev":"1-9be2e55e05ac368da3047841f301203d",
"language":"javascript",
"views":{ "by_id":{
"map" : "function(doc) { emit(doc.id, doc)}"
},"from_user_id":{
"map" : "function(doc) { if (doc.from_user_id) {emit(doc.from_user_id, doc)}}"},
"from_user":{
"map" : "function(doc) { if (doc.from_user) {emit(doc.from_user, doc)}}"},
"to_user_id":{
"map" : "function(doc) {if (doc.to_user_id){ emit(doc.to_user_id, doc)}}"},
"to_user":{
"map" : "function(doc) {if (doc.to_user){ emit(doc.to_user, doc)}}" },
"max_id":{
"map" : "function(doc) { if (doc.id) {emit(doc._id, eval(doc.id))}}",
"reduce" :"function(key,value) { a = value[0]; for (i=1; i <value.length; ++i){a = Math.max(a,value[i])} return a}"
}
}
}
when I try to 'PUT' this using curl:
curl -X PUT -d keys.json $CDB/_design/id
{"error":"bad_request","reason":"invalid UTF-8 JSON"}
I know it's not invalid JSON, because I tested it using the 'json' library built into Python 2.6, it loads fine. JS screw ups give me the error 'must evaluate to a function'
What else might be wrong with it?
© Stack Overflow or respective owner