Home » Create JSON with json_encode and json_decode using PHP

Create JSON with json_encode and json_decode using PHP

Create JSON with json_encode and json_decode using PHP

In this Post We Will Explain About is Create JSON with json_encode and json_decode using PHP With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Converting Object to JSON and JSON to Object in PHPExample

In this post we will show you Best way to implement Using PHP’s JSON encode and decode functions, hear for PHP and JSON – json_encode and json_decodewith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Read Also:  Receive JSON POST Data using PHP

Below is simple as well as a small example of PHP function json_encode() & json_decode().

Step 1: Create Json using PHP

<?php
$json_edata = array("client_details" => array(array("cname" => "Dhameliya Mayur", "salary" => "180000")), "work_post" => array(array("company_name" => "live24u", "role" => "Seniour Manager", "person" => "91")));
$live_json_encode = json_encode($json_edata);
echo $live_json_encode."<br/>";
?>

Step 2 : Decode the JSON : using json_decode() functions

<?php
$json_edata = array("client_details" => array(array("cname" => "Dhameliya Mayur", "salary" => "180000")), "work_post" => array(array("company_name" => "live24u", "role" => "Seniour Manager", "person" => "91")));
$live_json_encode = json_encode($json_edata);
echo $live_json_encode."<br/>";
 
$obj = json_decode($live_json_encode);
 
foreach($obj->client_details as $udetails){
    echo $udetails->cname;
    echo "<br/>";
    echo $udetails->salary;
    echo "<br/>";
}
foreach($obj->work_post as $wdetails){
    echo $wdetails->company_name;
    echo "<br/>";
    echo $wdetails->salary;
    echo "<br/>";
}
?>

Example

Read Also:  How to update multiple rows of multiple column in sql?

I hope you have Got What is php – Convert Object of class stdClass to JSON Object And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Convert and Loop through JSON with PHP and JavaScript Arrays/Objects | json to array php
  2. Read Also:  Converting JSON Object into Javascript PHP array
  3. Read Also:  laravel 6 Delete Multiple Records Eloquent
  4. Read Also:  cURL Requests with Laravel 6 using ixudra/curl
  5. Read Also:  PHP Convert Multidimensional Array To Object
  6. Read Also:  jQuery Ajax GET & POST REQUEST Methods PHP MySQLi
  7. Read Also:  How to Get the Current URL with VueJS?
  8. Read Also:  Magento Create custom Database Table with Module
  9. Read Also:  jQuery Parsing PHP JSON Data
  10. Read Also:  json to array php

Leave a Comment

Your email address will not be published. Required fields are marked *