Search code examples
reduxnormalizr

How do I move child objects of 'entities' up to the top level and rename 'results' object in normalizr?


Right now when I normalize this array:

[
   {
      "teamName":"abc",
      "description":"",
      "id":"123"
   },
   {
      "teamName":"def",
      "description":"",
      "id":"456"
   }
]

Normalizr outputs:

{
   "result":[
      "123",
      "456"
   ],
   "entities":{
      "teams":{
         "123":{
            "teamName":"abc",
            "description":"",
            "id":"123"
         },
         "456":{
            "teamName":"def",
            "description":"",
            "id":"456"
         }
      }
   }
}

Purely by modifying the schema, is there a way to output this instead?

{
   "queries":[
      "123",
      "456"
   ],
   "teams":{
      "123":{
         "teamName":"abc",
         "description":"",
         "id":"123"
      },
      "456":{
         "teamName":"def",
         "description":"",
         "id":"456"
      }
   }
}

I know I can pretty easily do this after the fact, but is there a built in way to adjust the structure of the outputted JSON data?


Solution

  • Normalizr is meant to give a standard response for all output with only two top level keys, results and entities. There are no options to do what you are requesting.