How to get values in different index position

Hi, I am running an external API where I get the results of what a customer purchased. The issue that I am having now is how to separate and get each item in order to add a record in the right fields.

The issue is that the JSON order depends on which position a customer picks an item, 2 different examples:

Example 1:

[

{

Size: 40,

colour: white,

types: [

skirt]},

{

Size: M,

colour: black,

types: [

sweater]},

{

Size: M,

colour: white,

types: [

Shirt]},

{

Size: 32/31,

colour: black,

types: [Trousers]}]

Example 2:

[

{

Size: 45,

colour: Brown,

types: [

shoes]},

{

Size: 34/32,

colour: black,

types: [

Trousers]},

{

Size: M,

colour: white,

types: [

Shirt]},

{

Size: L,

colour: White,

types: [Sweater]}]

As we can see in these 2 examples, the "trousers" and the "sweater" are in a different position.

Originally I thought having a function with a For each loop and add the single conditions, but this would be too long since I would have to add around 20/30 different product categories.

Is there a better way of doing this? Thank you very much in advance.

Working with APIs
3 replies