Weave 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

Json Path Laravel Package

symfony/json-path

Symfony JsonPath is a PHP component for navigating and querying JSON using JSONPath syntax per RFC 9535. Use JsonCrawler to evaluate paths, filter expressions, and extract values from complex JSON documents.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Feature Development: Accelerates implementation of dynamic JSON querying for APIs, reducing manual parsing logic in backend services (e.g., SaaS integrations, payment gateways). Enables real-time data extraction from nested JSON payloads without verbose loops or isset() checks.
  • Roadmap Alignment: Supports data-driven features like:
    • Analytics dashboards (e.g., querying nested metrics from API responses).
    • Configurable workflows (e.g., extracting dynamic fields from JSON configs).
    • Middleware pipelines (e.g., transforming JSON payloads before processing).
  • Build vs. Buy: Avoids reinventing JSONPath parsing (a solved problem in RFC 9535), saving 3–5 dev weeks and reducing technical debt. Aligns with Laravel’s ecosystem (Symfony components) for seamless integration.
  • Use Cases:
    • API Layer: Extract specific fields from third-party APIs (e.g., Stripe events, Shopify products) without hardcoding paths.
    • ETL Pipelines: Transform JSON data in batch jobs (e.g., migrating legacy databases to JSON).
    • Validation: Ensure required fields exist in JSON payloads (e.g., $.user.email).
    • Internal Tools: Build flexible query endpoints for support teams (e.g., GET /api/reports?path=$.metrics[*].value).
  • Release signal (v8.1.9): A patch release delivering parser/selector correctness fixes only — no new features, no deprecations, no breaking changes. Notable for roadmap confidence:
    • Fixes to key() escaping of backslashes and control characters, and to anchoring/slash escaping in match()/search() — meaning path expressions that previously misbehaved now resolve correctly, which broadens the set of safe query patterns (keys containing special characters, anchored regex filters).
    • Fix to index/slice selectors dropping null array elements — a data-integrity bug with real product impact: pipelines that count, index, or iterate array results could silently lose null entries. If any roadmap items depend on positional array semantics (e.g., "position N in a list", pagination offsets, aligned metrics arrays), that dependency is now safer.
    • Overall read for planning: the library is actively maintained and correctness-focused, which lowers the "abandoned dependency" risk commonly cited against smaller packages.

When to Consider This Package

  • Adopt if:
    • Your Laravel app frequently parses nested JSON (e.g., >50% of API responses require deep traversal).
    • You need standardized JSONPath support (RFC 9535) for consistency across teams.
    • Your stack is PHP/Laravel/Symfony (avoids polyfills or custom parsers).
    • You prioritize developer velocity over micro-optimizations (e.g., hand-written traversal).
    • You need positional/array-sensitive querying and are on ≥ v8.1.9 — earlier 8.1.x releases could drop null array elements in index and slice selectors, so pin the patched version or later.
  • Look elsewhere if:
    • You require non-standard JSONPath extensions (e.g., custom functions like $.sum()). Consider jsonpath-plus or spatie/array-to-xml for advanced use cases.
    • Your app is performance-critical (e.g., high-frequency trading). Benchmark against native json_decode() + manual loops for simple paths.
    • You’re using non-PHP stacks (e.g., Node.js, Python). Use native libraries (jsonpath for Python, jsonpath for JavaScript).
    • Your JSON is extremely large (e.g., >100MB). Stream parsing or database-native JSON functions (e.g., PostgreSQL’s jsonpath_query) may be better.
    • You need JSONPath modification (not just querying). Pair with spatie/laravel-json or write custom logic.
    • You are pinned below v8.1.9 and rely on index/slice selectors over arrays that may contain null values — treat that as a correctness blocker until upgraded, or stay with manual traversal for those paths.
  • Upgrade guidance: v8.1.9 is a safe, drop-in patch within the 8.1 line. For teams already using the package, schedule the bump alongside a regression test pass on path expressions containing escaped keys or regex filters, since behavior in those edge cases is corrected (outputs may change from "wrong" to "right").

How to Pitch It (Stakeholders)

Executives: "This package lets us query JSON data like a database—no more writing brittle nested if statements or manual loops to extract fields from API responses. For example, instead of hardcoding json_decode($response)['user']['profile']['name'], we’ll use JsonPath::search($response, '$.user.profile.name'). This cuts development time by 30–50% for JSON-heavy features, reduces bugs in parsing logic, and makes our APIs more maintainable. It’s a drop-in solution with zero operational overhead. The latest release (v8.1.9) is a maintenance patch that fixes three correctness bugs—special-character escaping in keys, filtering/anchoring edge cases, and a bug that could silently drop null entries from array results—with no breaking changes. That last fix matters because it protects our data pipelines from quietly losing records; upgrading is a low-risk, high-value hygiene step, not a re-platforming decision."

Engineering (Devs/Architects): *"Symfony’s JSONPath implementation is RFC 9535 compliant, battle-tested, and integrates seamlessly with Laravel. Key benefits:

  • Cleaner code: Replace 20+ lines of isset() checks with a single JsonPath::evaluate() call.
  • Reusable logic: Standardize JSON querying across APIs, jobs, and middleware.
  • Laravel-friendly: Works with HTTP clients, Eloquent, and Collections. Example:
    // Before (brittle)
    $user = json_decode($response)->user->profile->name;
    
    // After (declarative)
    $user = JsonPath::search($response, '$.user.profile.name');
    
  • Low risk: MIT-licensed, minimal footprint (~1MB), and backed by Symfony’s ecosystem. We can pilot it in non-critical paths (e.g., API response handlers) before rolling out globally."*

Engineering (v8.1.9 release note to forward to the team): *"Patch release — bug fixes only, no API changes:

  • JsonPath::key() now escapes backslashes and control characters correctly, so keys containing \, newlines, or other control chars are addressable.
  • match() / search() anchoring and slash escaping fixed — regex filters with anchors or escaped slashes now behave as specified.
  • Index and slice selectors no longer drop null array elements — previously, $[0] or $[1:3] could shift or lose results when the array contained null. If any pipeline counts or indexes array results, this is a silent data-loss bug; upgrade and add a regression test asserting null entries survive slicing. Action: bump to ^8.1.9, run the existing path-expression test suite, and spot-check any code that slices arrays or filters on regexes."*

Data/Analytics Teams: "This enables self-service JSON querying for reports and dashboards. For example, instead of writing custom scripts to extract $.metrics[*].value, analysts can use JSONPath directly in our internal tools. It also simplifies ETL pipelines by standardizing how we extract data from JSON sources. One caveat worth knowing: versions before 8.1.9 could silently drop null values when slicing arrays, which is exactly the kind of thing that skews a report without erroring. The fix is already in; we just need to confirm our extraction jobs run on the updated version and that any array-position assumptions are re-validated."

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.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc