Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten array of objects correctly #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

3-16
Copy link

@3-16 3-16 commented Aug 12, 2014

Given this JSON file:

   {
   "id":9,
   "namn":"CM 41",
   "artnr":70184628167,
   "beskr":"text",
   "title":"",
   "description":"",
   "typ":"1",
   "colorcode":0,
   "pris":12330,
   "img":"MasonrySaw_CM_41",
   "data":[
      {
         "id_data_info":2,
         "id_data_vrde":2,
         "info_text":"Spänning",
         "vrde_text":"230 V"
      },
      {
         "id_data_info":3,
         "id_data_vrde":70,
         "info_text":"Effekt",
         "vrde_text":"2,2 kW (3 Hk)"
      }
   ],
   "bladerecommendations":[

   ],
   "numbers-array":[
         1,
         2,
         3
   ],
   "strings-array":[
         "one",
         "two",
         "three"
   ]
}

The current implementation of flattenData gives the following in return:

{
   "id":9,
   "namn":"CM 41",
   "artnr":70184628167,
   "beskr":"text",
   "title":"",
   "description":"",
   "typ":"1",
   "colorcode":0,
   "pris":12330,
   "img":"MasonrySaw_CM_41",
   "data[]":[
      {
         "id_data_info":2,
         "id_data_vrde":2,
         "info_text":"Spänning",
         "vrde_text":"230 V"
      },
      {
         "id_data_info":3,
         "id_data_vrde":70,
         "info_text":"Effekt",
         "vrde_text":"2,2 kW (3 Hk)"
      }
   ],
   "propertys[]":[

   ],
   "bladerecommendations[]":[

   ],
   "uProducts[]":[

   ],
   "na[]":[
      1,
      2,
      3
   ],
   "sa[]":[
      "one",
      "two",
      "three"
   ],
   "active":false
}

If the value is an Array it should be sent to flattenData again, same as if it is an Object. This change gives the following return.

{
   "id":9,
   "namn":"CM 41",
   "artnr":70184628167,
   "beskr":"text",
   "title":"",
   "description":"",
   "typ":"1",
   "colorcode":0,
   "pris":12330,
   "img":"MasonrySaw_CM_41",
   "data[0][id_data_info]":2,
   "data[0][id_data_vrde]":2,
   "data[0][info_text]":"Spänning",
   "data[0][vrde_text]":"230 V",
   "data[1][id_data_info]":3,
   "data[1][id_data_vrde]":70,
   "data[1][info_text]":"Effekt",
   "data[1][vrde_text]":"2,2 kW (3 Hk)"
   "na[0]":1,
   "na[1]":2,
   "na[2]":3,
   "sa[0]":"one",
   "sa[1]":"two",
   "sa[2]":"three",
   "active":false
}

@3-16
Copy link
Author

3-16 commented Aug 12, 2014

This do not serielize correctly though...

{
   "id":9,
   "namn":"CM 41",
   "artnr":70184628167,
   "beskr":"text",
   "title":"",
   "description":"",
   "typ":"1",
   "colorcode":0,
   "pris":12330,
   "img":"MasonrySaw_CM_41",
   "data":{
      "0":{
         "vrde_text":"230 V",
         "id_data_info":"2",
         "id_data_vrde":"2",
         "info_text":"Spänning"
      },
      "1":{
         "id_data_info":"3",
         "id_data_vrde":"70",
         "info_text":"Effekt",
         "vrde_text":"2,2 kW (3 Hk)"
      }
   },
   "na":{
      "0":"1",
      "1":"2",
      "2":"3"
   },
   "sa":{
      "0":"one",
      "1":"two",
      "2":"three"
   },
   "active":false
}

@rhubarbselleven
Copy link
Contributor

Hi @3-16, thanks for this, could you address the test failures?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants