I must create a Json object that represent a Sandwich configuration (bread, meat, sauces etc...) from different arrays that contains the ingredients for each category (1 array for bread, 1 for meat etc...) like this {name: 'x', price: 'y'}
The categories are defined but each array can have a different number of elements.
It's possible to obtain, starting from these arrays, something like that by code? I need this to make a recap of my sandwich in the cart page after the user choose all the ingredients. (each cat_1 it's a type of ingredient).
sandwich{
"cat_1": {[
{
"name": "x",
"price": "x"
}
]
},
"cat_2": {[
{
"name": "x",
"price": "x"
}
]
},
"cat_3": {[
{
"name": "x",
"price": "x"
},
{
"name": "x",
"price": "x"
},
{
"name": "x",
"price": "x"
}
]
},
"cat_4": {[
{
"name": "x",
"price": "x"
},
{
"name": "x",
"price": "x"
}
]
},
"cat_5": {[
{
"name": "x",
"price": "x"
},
{
"name": "x",
"price": "x"
},
{
"name": "x",
"price": "x"
}
]
}
}
I don't post any code beacuse I don't know what can help.
Actually, I push all my arrays into a big array and I have something like that, but it's a lot different from what I want achieve.
[{
"name": "Montanaro",
"price": "5.00"
}, {
"name": "Manzo",
"price": "5.00"
}, {
"name": "Fossa",
"price": "1.00"
}, {
"name": "Caciotta",
"price": "1.00"
}, {
"name": "Guacamole",
"price": "0.50"
}, {
"name": "Olive ascolane",
"price": "1.00"
}, {
"name": "Mozzarelline fritte",
"price": "0.50"
}, {
"name": "Onion Rings",
"price": "1.00"
}]
I'm not a json expert so I don't know where to start...
Thank you to everyone that could help me.
Have a good day
cat_1,cat_2etc. coming from?