haphpiness

These are things in PHP which make me genuinely_happy();

Built-in JSON Support

JSON encoding and decoding is built into PHP core. No packages to install, no extensions to enable — it just works. Two functions, consistently named, with rich option flags.

// Encode — with formatting options
$data = ['users' => [['name' => 'Alice', 'age' => 30], ['name' => 'Bob', 'age' => 25]]];
$json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);

// Decode — returns associative arrays or objects
$decoded = json_decode($json, associative: true);  // Named argument!
echo $decoded['users'][0]['name']; // Alice

// Error handling (PHP 7.3+): throw on invalid JSON
$result = json_decode($input, flags: JSON_THROW_ON_ERROR);
// Throws JsonException instead of returning null silently

// Implement JsonSerializable for custom objects
class Money implements JsonSerializable {
    public function __construct(
        private int $cents,
        private string $currency,
    ) {}

    public function jsonSerialize(): mixed {
        return [
            'amount' => $this->cents / 100,
            'currency' => $this->currency,
        ];
    }
}

echo json_encode(new Money(1999, 'USD'));
// {"amount":19.99,"currency":"USD"}

The phpjson_encode and phpjson_decode functions handle all edge cases: Unicode, numeric precision, recursive structures, custom serialization. They're fast (PHP's JSON extension is implemented in C) and battle-tested across millions of applications.

Significance: Web-Native

PHP is a web language, and JSON is the web's data format. Having fast, reliable JSON support built into the language core means every PHP application can speak the lingua franca of web APIs without any additional dependencies.