I'm creating a function to export a JSON to a specified format. I need to include a square bracket within a single element. As you can see "details_order" contain a single element with curly brackets, i need to add an additional square brackets into it. Please advise, thanks
original code:
[ { "reference": "20190531", "orders": [ { "id": "12345", "label": "22776", "address": "ABC, Apple road", "details_orders": { "ref": "AB07-332C" } } ] } ]
expected code:
[ { "reference": "20190531", "orders": [ { "id": "12345", "label": "22776", "address": "ABC, Apple road", "details_orders": [ { "ref": "AB07-332C" } ] } ] } ]
When you encode your data structure into JSON format, just make sure the "ref" value is stored in an array inside the "details_orders" array.
Here's an example of how the data should be structured in PHP to output the desired JSON:
Here is how you could initialise such an array in PHP: