1

I am testing and learning CouchDB for a project. We want to load a series of JSON files into the DB. The problem I am having is the format of the JSON, as it has keys of "@". For example:

{
    "_id":"somestringhere",
    "@": [
           {
           "identifier":"somevalue",
           "somekey":"somevalue" 
           },
           {
           "somekey":"somevalue",
           "somekey":"somevalue"
           }
         ]
}

So I go to write my Map function to emit the value of the "@" like so:

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

This does not work and throws an error, as its not a valid identifier. What gives? I don't think it's a problem with JSON. More of a javascript error.

TyMayn
  • 1,896
  • 2
  • 18
  • 22

1 Answers1

1

After some further digging I found more information on javascript identifiers.

Why is the '@' symbol reserved in javascript and what is its purpose?

I was then able to access that node of the JSON with:

function(doc) {
  emit("document": doc['@']);
}
Community
  • 1
  • 1
TyMayn
  • 1,896
  • 2
  • 18
  • 22
  • 1
    I don't know how familiar you are with SO. But when you find the answer to your own question, you can validate it as 'the' answer. There is no problem with that. – Aurélien Oct 30 '13 at 14:10
  • 1
    Shouldn't it work also without the dot (`doc['@']`)? – Aurélien Oct 30 '13 at 14:10
  • Not also, but only! Thanks for keeping my brain churning. I have modified my answer to remove the `.` – TyMayn Oct 31 '13 at 17:19