{
"string": "hello",
"number": 42,
"float": 3.14,
"boolean": true,
"null": null,
"array": [1, 2, 3],
"object": { "key": "value" }
}$json = json_encode($data); // array → string
$data = json_decode($json, true); // string → array
// Check for errors:
if (json_last_error() !== JSON_ERROR_NONE) { ... }JSON: shorter, simpler to read and parse. XML: supports attributes, namespaces, schemas (XSD), better suited to complex documents. On the web, JSON has won.
A specification for describing and validating the structure of a JSON document. The equivalent of XSD for XML.