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,936
  • 2
  • 18
  • 23

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,936
  • 2
  • 18
  • 23