JSON Encoding and Decoding
Convert PHP arrays to JSON and parse JSON responses with json_encode/json_decode.
What is JSON?
JSON (JavaScript Object Notation) is a lightweight data format used for API communication and config files. PHP has built-in functions for encoding and decoding it.
json_encode()
Converts a PHP value (array, object, scalar) to a JSON string.
<?php
$data = ["name" => "Alice", "age" => 30, "active" => true];
$json = json_encode($data);
echo $json; // {"name":"Alice","age":30,"active":true}All lessons in this course
- JSON Encoding and Decoding
- Making HTTP Requests with cURL
- Handling API Responses and Errors
- Building a Simple API Client