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

Zend Json Laravel Package

zendframework/zend-json

Convenience utilities for encoding PHP data to JSON and decoding JSON back to native types, including helpers for advanced cases. Note: this Zend Framework repository was abandoned on 2019-12-31; development continues as laminas/laminas-json.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer: composer require zendframework/zend-json. Though archived and no longer under active development (last release: 3.1.2, 2019), it remains stable for JSON encoding/decoding in legacy Zend Framework or Laminas-migration projects. The primary entry points are Zend\Json\Json::encode() and Zend\Json\Json::decode(). Begin with these static methods to serialize PHP arrays/objects to JSON or parse JSON strings—especially useful when interoperating with older Zend Framework 2/3 apps or when migrating to Laminas where backward compatibility matters.

Key first use case: Use Json::encode($data) to serialize arrays/objects, and Json::decode($json, true) to convert JSON into associative arrays. For pretty-printing, use Json::prettyPrint($json, $indent = 4) to format JSON with consistent spacing (now preserves spaces after commas).

Implementation Patterns

  • Legacy integration: Use Json::decode($json, true) to convert JSON from external APIs into associative arrays in zf1/zf2-era controllers or models.
  • RPC handling: The component was historically used in Zend\Json\Server for JSON-RPC implementations; still relevant in legacy XML-RPC/JSON-RPC servers.
  • Strict mode: Prefer Json::encode($value, true) (second param = true) to disable E_STRICT warnings and ensure JSON_HEX tags are used—helpful when outputting JSON in error-prone environments.
  • Object casting: Use Json::encode($object) to serialize complex objects (including those with __sleep or custom serialization) without needing json_encode() fallbacks.
  • Laminas bridge: If migrating to Laminas, update autoloading; zendframework/zend-json is fully compatible with laminas/laminas-json as a drop-in replacement.
  • Pretty-printing: Use Json::prettyPrint() for human-readable JSON output, now correctly preserving spaces after commas (e.g., {"key": "value", "nested": {"foo": "bar"}} instead of {"key": "value","nested":{"foo":"bar"}}).

Gotchas and Tips

  • Deprecation warning: Though not deprecated, it’s archived—plan for eventual migration to laminas/laminas-json.
  • PHP 7.4 compatibility: Release 3.1.2 fixes an issue where curly braces ({}) in JSON array/object access were causing problems under PHP 7.4. No action is required unless you were explicitly relying on non-standard JSON syntax.
  • Performance: Json::decode() with true as second arg is marginally slower than native json_decode() due to extra validation; for high-throughput endpoints, prefer native functions.
  • Security: Do not use Json::decode() for untrusted input unless Zend\Json::setEvalMethods(false) (default) is set—prevents accidental code execution via JSONP.
  • Extension point: The package uses Zend\Json\Exception namespaces—ensure your error handling catches Exception\RuntimeException or Exception\InvalidArgumentException as needed.
  • Autoloading: If using Composer autoloader, verify PSR-4 alignment; older ZF apps might still rely on Zend/Json.php paths.
  • Pretty-print quirks: While Json::prettyPrint() now preserves spaces after commas, avoid relying on this for machine-generated JSON (e.g., APIs) where strict formatting is required.
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
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
uri-template/tests