JSON (JavaScript Object Notation) is a lightweight data-interchange format used to exchange data between client and server in web applications.
// JSON object structure example
{
"name":"John",
"age":30,
"isStudent":false,
"skills":["PHP","JavaScript","MySQL"],
"address":{"city":"New York","zip":"10001"}
}
// Converting JSON string to JavaScript object and back
let jsonString='{"name":"Alice","age":25}';
let obj=JSON.parse(jsonString);
console.log(obj.name);
let newJson=JSON.stringify(obj);
console.log(newJson);
// Encoding and decoding JSON in PHP
<?php
$data=array("name"=>"Bob","age"=>28,"skills"=>array("PHP","Laravel"));
echo json_encode($data);
$jsonString='{"name":"Eve","age":22}';
print_r(json_decode($jsonString,true));
?>