Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laminas Json Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Hydrator Integration: Often used in combination with Laminas\Stdlib\Hydrator to serialize/deserialize objects for REST APIs (e.g., Laminas\Hydrator\JsonStrategy).
  • Safe Decoding with Exception Handling: Wrap 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
    }
    
  • Deterministic Serialization: Use Json::encode() when object property order matters (e.g., for signature generation) — it respects array key order when encoding associative arrays.
  • Class Name Filtering: When decoding, pass 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).

Gotchas and Tips

  • Archived ≠ Broken, but Avoid New Projects: The package is frozen. Prefer native json_encode/json_decode for new apps unless you depend on downstream laminas/laminas-* components that still rely on it.
  • Type Handling Quirks: Json::decode() defaults to Json::TYPE_OBJECT; always explicitly specify Json::TYPE_ARRAY for array-based workflows to avoid runtime type errors.
  • No Strict Type Checking: isJson() is loose — it only checks for { or [ at start. Don’t use it for validation; validate schema separately.
  • Unicode Escaping Behavior: By default, 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).
  • Performance: Slightly slower than native functions due to extra validation and abstraction — not suitable for high-throughput micro-batching unless cached.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation