How to use cURL to Get JSON Data and Decode JSON Data in PHP ? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report In this article, we are going to see how to use cURL to Get JSON data and Decode JSON data in PHP.cURL: It stands for Client URL.It is a command line tool for sending and getting files using URL syntax.cURL allows communicating with other servers using HTTP, FTP, Telnet, and more.Approach:We are going to fetch JSON data from one of free website, which gives JSON data for testing i.e. reqres.inFirst, we initialize curl using curl_init() method.Sending GET request to reqres.in server using curl_setopt() method with CURLOPT_URL to get json data.After that, we have to tell curl to store json data in a variable instead of dumping on screen. This is done by using CURLOPT_RETURNTRANSFER parameter in curl_setopt() function.Execute curl using curl_exec() method.At last, close the curl using curl_close() method.Example: PHP <?php // Initializing curl $curl = curl_init(); // Sending GET request to reqres.in // server to get JSON data curl_setopt($curl, CURLOPT_URL, "https://reqres.in/api/users?page=2"); // Telling curl to store JSON // data in a variable instead // of dumping on screen curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Executing curl $response = curl_exec($curl); // Checking if any error occurs // during request or not if($e = curl_error($curl)) { echo $e; } else { // Decoding JSON data $decodedData = json_decode($response, true); // Outputting JSON data in // Decoded form var_dump($decodedData); } // Closing curl curl_close($curl); ?> Output: Comment A asmitsirohi Follow 2 Improve A asmitsirohi Follow 2 Improve Article Tags : Web Technologies PHP PHP-function JSON PHP-cURL PHP-Questions +2 More Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like