php json encode
snippet in php

php json_decode

user6655

$personJSON = '{"name":"Johny Carson","title":"CTO"}';

$person = json_decode($personJSON);

echo $person->name; // Johny Carson

php json encode

user3534

$person = array( 
    "name" => "Johny Carson", 
    "title" => "CTO"
); 
$personJSON=json_encode($person);//returns JSON string

json_encode php

user224

<?php 
   
// Declare an array  
$value = array( 
    "name"=>"GFG", 
    "email"=>"abc@gfg.com"); 
   
// Use json_encode() function 
$json = json_encode($value); 
   
// Display the output 
echo($json); 
   
?> 

json_encode php

user9939


  <?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

  
echo json_encode($age);
?>
 

php echo json

user4569

<?php
$data = ['name' => 'John', 'age' => 35];
header('Content-type: Application/json');
echo json_encode($data);