Question: How can i wrap my return array into string in laravel?
Some thing like this

Laravel:

```
    $columnDefinitions = array();

    $columnDefinition = new \stdClass();
    $columnDefinition->label = "No";
    $columnDefinition->sortable = true;
    $columnDefinition->thClass = 'width-50';
    $columnDefinition->tdClass = 'text-center';
    //end add custom css
    $columnDefinitions["index_number"] = $columnDefinition;
    return $columnDefinitions;

```

Expected result

```
'[{
   apple: {
             label: "No"
             sortable: true
             tdClass: "text-center"
          }
}]'

```

Answer: 
As per the Laravel Documentation you can directly send the `json` response from your method

> 
> The json method will automatically set the `Content-Type` header to
>  `application/json`, as well as convert the given array to JSON using the
>  `json_encode` PHP function:
> 
> 
> 

```
return response()->json([
    // You can pass your array values here
]);

```

[Laravel -> Http Responses -> Json Responses](https://laravel.com/docs/5.8/responses#json-responses)
use this:

```
$columnDefinition = new stdClass();
$columnDefinition->label = "No";
$columnDefinition->sortable = true;
$columnDefinition->thClass = 'width-50';
$columnDefinition->tdClass = 'text-center';

$column = new stdClass;
$column->apple = $columnDefinition;

$finalArray = [$column];
//end add custom css
return json_encode($finalArray);

```