To Create and Parse JSON data in PHP :
We can use json_encode() function of PHP to create JSON data format. Below is the PHP snippet to create the JSON data format of given array of PHP :

Example :

$json_data = array(
	        "id" => 1,
	     	"name" => "Rahul Yadav",
	     	"country" => "India",
	     	"email" => "",
	     	"frameworks" => array(
$json_string = json_encode($json_data);
echo $json_string;


 Output :

 {"id":1,"name":"Rahul Yadav","country":"India","email":"","frameworks":["Codeigniter","Laravel"]}


We can use json_decode() function of PHP to parse the JSON data. Below code will parse the JSON data into PHP arrays.

Example :

$json_string='{"id":1,"name":"Rahul Yadav","country":"India","email":"","frameworks":["Codeigniter","Laravel"]}';
//print the parsed data
echo $obj->id."
"; // displays 1 echo $obj->name."
"; // displays Rahul Yadav echo $obj->country."
"; // displays India echo $obj->email."
"; //displays echo $obj->frameworks[0]."
"; // displays Codeigniter echo $obj->frameworks[1]."
"; // displays Laravel ?> /* Output : 1 Rahul Yadav India Codeigniter Laravel */
Rahul Yadav

Technical Architect

Kuala Lumpur, Malaysia

Connect Me:     

I'm a Full Stack Web Developer working in a MNC and passionate of developing modern web and mobile applications.

I have designed and developed CodephpOnline & CodephpOnline Wiki platform to expatiate my coding, technical and digital learning experiences.

In my leisure time, I write articles on web development such as PHP, Laravel, CodeIgniter, Mediawiki, Magento, Linux, Angular, Ionic, ReactJS, NodeJS, Cloud and more.

Tag Cloud