0

This is a generated response from a search server. But it generates the same response values twice (see 'prodid' of both response blocks - they are the same), instead of using nested arrays. How can I parse this into a single element. The response can vary greatly in the number of same id's and needs to be parsed into a single element for each unique id - multiple values with same id should be put into the same element.

Thanks in advance

{
"searchquery": "wide fit running shoes",
"timetaken": 1.607,
"size": 3,
"array": [{
    "prodid": 902,
    "prodtitle": "Naturalizer Scout Wide Open Toe Slingback Sandals Shoes Blue Womens New/Display",
    "mtype": "shoe",
    "expkey": "running",
    "price": 75.00,
    "imgurl": "http://ecx.images-amazon.com/images/I/31lStgJu2AL._SY395_.jpg",
    "5count": 0,
    "4count": 2,
    "1count": 0,
    "2count": 1,
    "3count": 1,
    "buyurl": "http://someurl.com"
}, {
    "prodid": 902,
    "prodtitle": "Naturalizer Scout Wide Open Toe Slingback Sandals Shoes Blue Womens New/Display",
    "mtype": "shoe",
    "expkey": "fit",
    "price": 75.00,
    "imgurl": "http://ecx.images-amazon.com/images/I/31lStgJu2AL._SY395_.jpg",
    "5count": 0,
    "4count": 16,
    "1count": 0,
    "2count": 14,
    "3count": 14,
    "buyurl": "http://someurl.com"
}]
}

For eg. prodid:902 is a single search result and needs to be shown only once - and needs to be parsed in such a way but the expkey and count values of both should be in the same element

enter image description here

The render looks like this right now - the values are repeating - i need it to be rendered only once, but with data from both - see expkey and Xcount in the JSON

Annu
  • 49
  • 8
  • "the expkey and count values of both should be in the same element" How? – str Jun 18 '17 at 10:11
  • 1
    It is unclear what result you want, can you give an example what the result should look like? – Endenite Jun 18 '17 at 10:11
  • If you want to merge objects, see this question https://stackoverflow.com/a/171256/5385381 – ksav Jun 18 '17 at 10:11
  • @Annu how we can merge values of the same keys? Do we need overwrite ? Or we must create new array with values? – Farkhat Mikhalko Jun 18 '17 at 10:12
  • I dont know how to explain it properly. The problem is the data should be parsed in such a way that _prodid_ 902 as you see in the question repeats twice, but the values inside change - such as the Xcount and expkey - which should be parsed and displayed one single time - instead of twice seperately – Annu Jun 18 '17 at 10:13
  • @MihalkoFarhat Can you please look at the above explanation – Annu Jun 18 '17 at 10:17
  • @HermanLauenstein I tried to explain above. Please take a look – Annu Jun 18 '17 at 10:17
  • 1
    What should the _JSON_ result look like? – Endenite Jun 18 '17 at 10:28
  • @HermanLauenstein i've given the JSON response above in the question, it needs to be rendered in HTML like i said – Annu Jun 18 '17 at 10:32
  • You haven't shown how example data should be rendered with regard to differences of counts and expkey. Also haven't outlined what properties would always be common. We can't help when we don't know what expected results are and that would start by restructuring the data – charlietfl Jun 18 '17 at 10:37

0 Answers0