I have the following JSON that works on Postman when performing a POST request:
'{
"bar1": "sample",
"bar2": [
{
"bar1": "sample",
"bar2": "sample",
"bar3": "111111111",
"bar4": "sample",
"bar5": {
"bar6": "varr",
"bar7": [
-70.11111111111111,
-33.11111111111111
]
}
}
],
"bar8": 11111
}'
However on my backend I have an Array that I need to shape into that JSON format. The way I am building my array is as follow:
$myArray =array(
"bar1" => "sample",
"bar2" => (object) array(
"bar1" => "sample",
"bar2" => "sample",
"bar3" => "111111111",
"bar4"=> "sample",
"bar5" => (object)[
"bar6" => "varr",
"bar7" => array(
-70.111111111111111,
-33.111111111111111
)]
),
"bar8" => 11111
) ;
When it comes to send the request through cURL I get "Internal server error" as response. If I were to send the JSON raw string, I would get the correct response. What would be the best way to convert my Array into the JSON I need?
json_encode() gives me the following JSON, which resolves into a server error when making request.
{
"bar1": "sample",
"bar2": {
"bar1": "sample",
"bar2": "sample",
"bar3": "sample",
"bar4": "sample",
"bar5": {
"bar6": "varr",
"bar7": [
-70.111111111111,
-33.111111111111
]
}
},
"bar8": 11111
}