Creating and Parsing JSON Data

Create the JSON data from php array

<?php
   
   $jsonData = array ('id'=>1, 'category'=>'Programming Languages', 'name'=>'Php',  'type'=>'Server Side');
   
   echo json_encode($jsonData);
?>

Parsing JSON data

<?php

    $jsonData='{"id":1,"category":"Programming Languages","name":"Php","type":"Server Side"}';
    $obj = json_decode($jsonData);

    //print the parsed data
    echo $obj->name; //print Php
    echo $obj->id; //print 1

?>

Do you find this helpful?

Related articles