How to return Json data array with PHP/Laravel?

  arrays, json, laravel, php

I’m devoloping an api with Laravel and I have to get the data of a json file in a url, this is my code:

public function index(){
    $json_file=file_get_contents("url that I'm using");
    $json_str = json_decode($json_file);
    echo $json_str;

The JSON file:

  "clients": [
       "name": "Tyler Durden",
       "job": "leader of the ..."

But when I access my route that call the index() I get this error:

Object of class stdClass could not be converted to string

I want to get any pair of clients and save them, can someone help me?

Source: Laravel

Leave a Reply