0

I have a bunch of projects in my database, and I'd like to place them into 4 separate groups.

At first, I made four different groups and then just placed each project into the corresponding group. But when I add them into Google Firebase through my JSON structure, it automatically gives each of them the id of '0', '1', '2' etc.

This poses a problem because when I try to use lunr.js, I require to keep a store dictionary that holds each reference name and its information inside it. Like this:

var doc={
    name: snapshot.val().name;//This will be '0', '1', '2' etc.
}
store[doc.name] = {info: here} //Which will keep overwriting old files inside this store

I have a global store[ ] dictionary that will hold all the projects, but my JSON has a structure like this:

{
  featured{
    0{...},
    1{...},
  },
  other{
    0 : {...},
    1 : {...},
    2 : {...}
  }
}

I go through each group (featured, other etc.) and add them to my index, but the store[ ] dictionary is overwritten since they have the same keynames.

This tells me my JSON structure is a little flawed, so is there a better way to structure it?

Homerdough
  • 353
  • 1
  • 3
  • 12
  • I think JSON doesn't allow functions http://stackoverflow.com/a/2001471/2813224 – zer00ne Aug 02 '16 at 20:30
  • I'm importing a JSON file into a database, and using Javascript to interact with it, hence the function. – Homerdough Aug 02 '16 at 20:37
  • So your not using doc as JSON? Ok, make sure you double quote your keys. (e.g. `other{ "0" : {...}, "1" : {...}, "2" : {...}` http://stackoverflow.com/documentation/javascript/416/json#t=201608022043084784899 – zer00ne Aug 02 '16 at 20:42
  • the actual JSON structure works fine, syntax-wise. I'm talking about in practice, iterating through each 'group' (ie, featured, spaces, other etc.) and trying to add them into the store[ ] dictionary won't work out because each 'group' will have members with the same names, thus overwriting the dictionary. Is there a better way to structure the JSON? Like for all the projects, have a 'groups' tab and tell which group it should be filed under? – Homerdough Aug 02 '16 at 20:50
  • One thing comes to mind is using arrays since a solid index of key/values is a guarantee that everything is in order and in it's place regardless of whether names are duplicated or not. – zer00ne Aug 02 '16 at 21:11

0 Answers0