Skip to content

ElastiCache (Redis OSS + Valkey engines) JSON.GET JSONPath filter works for top-level fields, but fails for nested fields in predicate (Invalid JSON path)

0

Amazon ElastiCache JSON (Redis OSS and Valkey engines) supports JSONPath filters for top-level fields such as:

JSON.GET key '$.transactions[?(@.state=="Posted")]'

…but fails when the predicate references a nested field, even though this is valid JSONPath and works in OSS Redis/Valkey locally (Docker).

Example that works locally but fails on ElastiCache:

JSON.GET key '$.transactions[?(@.installment_details.eligibility=="Eligible")]'

ElastiCache returns:

(error) SYNTAXERR Invalid JSON path

This appears to be either:

  • a bug in ElastiCache’s JSONPath parser, or
  • a missing feature despite AWS documentation stating compatibility with JSON module v2 / JSONPath support.

AWS docs indicate ElastiCache supports JSONPath filters and is compatible with version 2 of the JSON module.

Sample data used:

JSON.SET user:demo '$' '{
  "transactions": [
    {
      "id": "TXN-9001",
      "state": "Posted",
      "amount": "125.00",
      "currency": "USD",
      "installment_details": {
        "eligibility": "Eligible"
      }
    },
    {
      "id": "TXN-9002",
      "state": "Pending",
      "amount": "30.00",
      "currency": "USD",
      "installment_details": {
        "eligibility": "Ineligible"
      }
    }
  ]
}'

Queries tested

I have attempted many permutations of queries that work locally but do not work on elasticache. Her is a sample of those queries:

JSON.GET user:demo '$.transactions[?(@.installment_details.eligibility=="Eligible")]'
JSON.GET user:demo '$["transactions"][?(@["installment_details"]["eligibility"]=="Eligible")]'
JSON.GET user:demo '$.transactions[*][?(@["installment_details"]["eligibility"]=="Eligible")]'
JSON.GET user:demo '$.transactions[?(@.installment_details.["eligibility"]=="Eligible")]'
JSON.GET user:demo '$.transactions[?(@.installment_details && @.installment_details.["eligibility"]=="Eligible")]'

all return one of the following errors:

(error) SYNTAXERR Invalid JSON path

or

(error) SYNTAXERR Array index is not a number

Questions

  • Is this a known limitation or bug in ElastiCache’s JSONPath implementation?
  • If it’s a limitation, what engine/version supports nested dereference in filter predicates?

asked 9 months ago129 views

2 Answers
0

This appears to be a limitation in ElastiCache's implementation of JSONPath filtering. While ElastiCache for Redis OSS and Valkey does support JSONPath and is compatible with version 2 of the JSON module, there are some differences in how it handles complex path expressions.

Based on the documentation, ElastiCache can directly filter array objects, but the examples shown in the documentation are simpler than what you're trying to achieve. The documentation shows examples like $[?(@<4)] or $.my_key[?(@<4)] where the filter condition is a direct comparison without nested field references.

The error messages you're receiving ("Invalid JSON path" or "Array index is not a number") suggest that ElastiCache's JSONPath implementation doesn't support the nested field dereferencing within filter predicates that you're attempting to use.

As a workaround, you might need to:

  1. Retrieve the entire transactions array first and then filter client-side
  2. Use multiple JSON commands to navigate the structure step by step
  3. Consider restructuring your data to flatten the nested attributes you need to filter on

The documentation doesn't explicitly mention support for nested field references in filter predicates, which suggests this might be a limitation rather than a bug. The JSON support in ElastiCache requires Valkey 7.2+ or Redis OSS 6.2.6+, but there's no indication that higher versions would support this specific functionality.
Sources
Getting started with JSON for Valkey and Redis OSS - Amazon ElastiCache
JSON data type overview - Amazon ElastiCache

answered 9 months ago

EXPERT

reviewed 9 months ago

0

This is a known limitation of Amazon’s managed JSON implementation, not a bug in your queries. In Amazon ElastiCache (both Redis OSS and Valkey engines), the JSON module is not feature-complete with upstream RedisJSON v2, even though AWS documentation describes “JSONPath support.” Specifically, ElastiCache’s JSONPath parser only supports single-level field dereferencing inside filter predicates. Any predicate that requires nested object traversal (for example @.installment_details.eligibility) fails during parse time with SYNTAXERR Invalid JSON path. This is why all syntactic variations you tried fail: the limitation is structural, not syntactic. Upstream RedisJSON (and Valkey JSON) support nested dereference in predicates because they use a newer JSONPath evaluator; ElastiCache currently uses a restricted fork optimized for safety and performance, and nested predicates are intentionally unsupported. There is no ElastiCache engine version today (as of Redis OSS 7.x / Valkey 7.x) that enables this capability. Workarounds:

  • Denormalize the nested field (e.g., copy installment_details.eligibility to a top-level field).
  • Filter client-side after fetching $.transactions[*].
  • Use secondary indexing patterns (e.g., maintain sets keyed by eligibility).
  • If full JSONPath compliance is required, run self-managed Redis/Valkey (EC2, EKS, or containers).

answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.