0Pricing
PHP Academy · Lesson

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

  1. JSON Encoding and Decoding
  2. Making HTTP Requests with cURL
  3. Handling API Responses and Errors
  4. Building a Simple API Client
← Back to PHP Academy