laminas/laminas-json
Abandoned Laminas JSON component. Provided utilities for encoding/decoding JSON and related helpers, but it will receive no further development. See Laminas TSC minutes for details and consider migrating to supported alternatives.
Start by installing via Composer: composer require laminas/laminas-json. Despite the package being archived (as of 2026), it remains functionally stable for legacy projects or environments where JSON encoding/decoding must avoid json_encode()/json_decode() directly (e.g., for handling Laminas\Stdlib\Hydrator or zf-class name serialization). The most common first use is:
use Laminas\Json\Json;
// Encode PHP array to JSON
$json = Json::encode(['name' => 'Alice', 'role' => 'admin']);
// Decode JSON to PHP associative array
$data = Json::decode($json, Json::TYPE_ARRAY);
Check the Laminas\Json\Json class for encode(), decode(), and isJson() methods — these are the core APIs you’ll use daily.
Laminas\Stdlib\Hydrator to serialize/deserialize objects for REST APIs (e.g., Laminas\Hydrator\JsonStrategy).decode() in try/catch to handle malformed JSON gracefully:
try {
$data = Json::decode($rawPayload, Json::TYPE_ARRAY);
} catch (\Laminas\Json\Exception\SyntaxException $e) {
// Return 400 Bad Request
}
Json::encode() when object property order matters (e.g., for signature generation) — it respects array key order when encoding associative arrays.Json::TYPE_ARRAY to avoid creating stdClass objects, or use custom object hydration via Json::decode($json, false, $classMap) where $classMap maps class names to classes (deprecated in newer forks, but preserved here).json_encode/json_decode for new apps unless you depend on downstream laminas/laminas-* components that still rely on it.Json::decode() defaults to Json::TYPE_OBJECT; always explicitly specify Json::TYPE_ARRAY for array-based workflows to avoid runtime type errors.isJson() is loose — it only checks for { or [ at start. Don’t use it for validation; validate schema separately.encode() escapes non-ASCII characters (\uXXXX). To preserve UTF-8, pass JSON_UNESCAPED_UNICODE via the third param: Json::encode($data, null, JSON_UNESCAPED_UNICODE).How can I help you explore Laravel packages today?