I want my json to start with { but if using json_encode it is getting converted into string, I am using php7.1 on ubuntu and working on magento 2.3
This is what I am getting with the below code, I don't want '['
[
{
"success": "true",
"data": {
"mainimages": [
{
Here is my code
$response = array(
array(
"success" => "true",
"data" => $alldata,
"newarrivalheading" => "NEW ARRIVALS",
"instagramheading" => "CELEBS IN LULU",
"specialpriceheading" => "SPECIAL PRICES",
"editorwishlistheading" => "EDITOR'S WISHLIST",
"stylehighlightheading" => "STYLE HIGHLIGHTS",
"styletagline" => "#Looks to swipe right",
"newarrivalindex" => 3,
"instagramindex" => 9,
"editorwishlistviewall" => "",
"sliderimage" => $sliderimage
)
);
return $response;
This is what I want
{
"success": "true",
"data": {
"mainimages": [
{
So remove the unnecessary outer array like so
$alldata = [1,2,3,4];
$sliderimage = ['xz.jpg','ab.png'];
$response = array(
"success" => "true",
"data" => $alldata,
"newarrivalheading" => "NEW ARRIVALS",
"instagramheading" => "CELEBS IN LULU",
"specialpriceheading" => "SPECIAL PRICES",
"editorwishlistheading" => "EDITOR'S WISHLIST",
"stylehighlightheading" => "STYLE HIGHLIGHTS",
"styletagline" => "#Looks to swipe right",
"newarrivalindex" => 3,
"instagramindex" => 9,
"editorwishlistviewall" => "",
"sliderimage" => $sliderimage
);
echo json_encode($response);
RESULT
{
"success": "true",
"data": [
1,
2,
3,
4
],
"newarrivalheading": "NEW ARRIVALS",
"instagramheading": "CELEBS IN LULU",
"specialpriceheading": "SPECIAL PRICES",
"editorwishlistheading": "EDITOR'S WISHLIST",
"stylehighlightheading": "STYLE HIGHLIGHTS",
"styletagline": "#Looks to swipe right",
"newarrivalindex": 3,
"instagramindex": 9,
"editorwishlistviewall": "",
"sliderimage": [
"xz.jpg",
"ab.png"
]
}