Published on

How to Get Json Data From url in Laravel

  • avatar
    Md Rathik

I'll demonstrate how to retrieve JSON from a URL in a php script in this tutorial. JSON has gained popularity as a format for data sharing and web service outputs. PHP makes it pretty easy to perform an HTTP request and parse a JSON response from a URL, however beginners could find learning how to parse json challenging.

i will use an sample json url to retrive data by using this code.

  1. Its the script that you can copy and return the data. You can directly copy this code and enter your function & run that.
//set your json url
$url = "";

//call the api url
$json = file_get_contents($url);
$json = json_decode($json);

  1. Now you will get the results like this & you can use this where you need.
  "userId": 1,
  "id": 1,
  "title": "delectus aut autem",
  "completed": false

Read my others post

Dont forget to comment if need any help