Online Tool Store Online Tool Store
{ } Developer Tools

· 4 min read

How to Query JSON With JSONPath Expressions

Heshan Fernando

Co-founder & COO

Heshan Fernando is the Co-founder and Chief Operating Officer of Ceyentra Technologies, where he leads project management, engineering, and research and development strategy. With over nine years of industry experience, he is passionate about transforming complex customer challenges into practical, high-impact solutions. His customer-centric leadership has enabled multidisciplinary teams to consistently deliver secure, scalable, and industry-grade digital products that create lasting business value. View on LinkedIn

Share

How to Query JSON With JSONPath Expressions

You’re working with a deeply nested JSON API response and need to pull out a specific value — or every value matching a pattern — buried several levels deep, without writing custom parsing code just to extract one field. JSONPath is exactly the tool for this: a query language for JSON, similar in spirit to how XPath queries XML, that lets you express “give me this specific nested value” or “give me every item matching this pattern” as a compact expression rather than manual traversal code.

The syntax, though, isn’t something most people have memorized, and getting a JSONPath expression right on the first try against real, complex data usually takes some trial and error.

What JSONPath querying actually involves

JSONPath expressions navigate JSON structure using a compact syntax: $ represents the root, . or [] accesses a specific property, [*] is a wildcard matching every item in an array or object, and .. performs recursive descent, searching at any depth rather than just the immediate level. Combined, these let you express queries like “every price field, anywhere in this document, regardless of nesting depth” in a single short expression rather than writing a recursive traversal function.

Testing against real data matters because JSONPath’s behavior on edge cases — arrays of mixed types, missing fields, deeply nested wildcards — isn’t always obvious just from reading the syntax rules. Seeing the actual matched results against your specific data confirms the expression does what you intended before you build real code around it.

Why people get stuck here

  • JSONPath syntax isn’t intuitive without practice. The combination of dot notation, bracket notation, wildcards, and recursive descent takes some getting used to, especially for less common query patterns.
  • Complex nested data makes manual verification hard. Checking by eye whether a query correctly matched everything intended, across a large or deeply nested document, isn’t practical without tooling.
  • Different JSONPath implementations have minor variations. Not every library implements the specification identically, which can cause a query that works in one context to behave slightly differently in another.
  • Trial and error is the normal way to build a working query. Getting a JSONPath expression exactly right on the first attempt, especially for a complex extraction, isn’t typical — testing against real data is how it’s usually refined.

What a good JSONPath tester looks like

Evaluates expressions against real, editable JSON

Testing against your actual data structure (or a representative sample) gives results that translate directly to your real use case, not an abstract example.

Supports the core JSONPath features

Property access, wildcards, and recursive descent cover the vast majority of practical query needs.

Shows results instantly as you refine the expression

Immediate feedback while adjusting a query lets you iterate quickly toward the exact extraction you need.

Common mistakes to avoid

  • Assuming a JSONPath expression is correct without testing it against representative real data, including edge cases like missing or differently-typed fields.
  • Confusing dot notation and bracket notation syntax, which can produce a query that looks plausible but doesn’t actually match as intended.
  • Not accounting for arrays when writing a query meant to also match object properties, or vice versa.
  • Building complex application logic around an untested JSONPath expression, only to discover an edge case it doesn’t handle once it’s already in use.

How to do it with the JSON Path Tester

Online Tool Store’s JSON Path Tester evaluates JSONPath expressions against your data entirely in your browser.

  1. Paste in your JSON data.
  2. Write a JSONPath expression.
  3. See the matched results instantly.
  4. Refine the expression until it extracts exactly what you need.

Because it runs locally, you can test against real API response data without sending it to an external server.

Frequently asked questions

What’s the difference between . and [*] in JSONPath?

. (or .propertyName) accesses a specific named property, while [*] is a wildcard that matches every item in whatever array or object it’s applied to — use . when you know the exact field name, and [*] when you want every item at that level regardless of name or index.

What does the .. (recursive descent) operator do?

It searches for matches at any depth in the JSON structure, not just the immediate level — useful for finding every occurrence of a field name regardless of how deeply nested it is within the document, without needing to know or specify the exact path to each occurrence.

Why does my JSONPath expression work differently in another tool or library?

Different JSONPath implementations sometimes have minor variations in how they handle certain edge cases, since JSONPath (unlike JSON itself) doesn’t have one single, universally implemented formal specification — if you’re moving a tested expression into actual application code, verify it behaves the same way in that specific library.

Final thought

JSONPath turns “manually write a function to dig this value out of nested JSON” into a compact, reusable expression — worth the small learning curve once you’re regularly working with API responses or configuration data that isn’t flat.

Try the free JSON Path Tester

#json-path-tester#jsonpath-evaluator#jsonpath-online#query-json-with-jsonpath#online-tools#free-tools