What are common JSONPath errors and how do I fix them?
Understanding common JSONPath errors helps you write correct expressions faster.
Error: "Path not found" or Empty Results
Causes:
- Incorrect property names (case-sensitive!)
- Wrong array indices
- Missing properties in data
- Incorrect syntax
Solutions:
- Verify property names:
❌ $.User.Name (wrong case)
✅ $.user.name (correct case)
- Check array structure:
❌ $.items.products[0] (items is array, not object)
✅ $.items[0].products
- Use recursive descent to find fields:
$..name (finds "name" at any level)
- Handle optional fields: Check if the field exists in your JSON before querying
Error: "Invalid expression syntax"
Common syntax mistakes:
- Missing
$at start:
❌ users[0].name
✅ $.users[0].name
- Incorrect filter syntax:
❌ $.books[@.price < 10]
✅ $.books[?(@.price < 10)]
- Wrong bracket usage:
❌ $.users.0.name
✅ $.users[0].name
- Unescaped special characters:
❌ $.data.user-id
✅ $.data['user-id']
Error: "Unexpected results"
Issue: Getting objects instead of values
// If you want just the values:
❌ $.books[*] // Returns full objects
✅ $.books[*].title // Returns just titles
Issue: Filter not working
// Ensure proper comparison syntax:
❌ $.books[?(@.price = 10)] // Single = (assignment)
✅ $.books[?(@.price == 10)] // Double == (comparison)
// Check data types:
❌ $.books[?(@.price == "10")] // String comparison
✅ $.books[?(@.price == 10)] // Number comparison
Error: "Too many results"
Problem: Expression matches more than expected
Solutions:
- Be more specific:
❌ $..name (all names everywhere)
✅ $.users[*].name (only user names)
- Add filters:
❌ $.products[*]
✅ $.products[?(@.category == 'electronics')]
- Limit by index:
❌ $.items[*]
✅ $.items[0:10] (first 10 only)
Debugging Tips:
- Start simple and build up:
$ // Full document
$.users // All users
$.users[0] // First user
$.users[0].name // First user's name
- Use this tool's features:
- Check the match count
- Inspect the full path of each result
- Load example data to understand syntax
-
Validate your JSON first: Invalid JSON will cause all queries to fail
-
Test filter conditions separately:
// First verify the field exists:
$.books[*].price
// Then add filter:
$.books[?(@.price < 20)]
- Check array vs object:
// If "users" is an array:
$.users[*].name ✅
// If "users" is an object:
$.users.name ✅
Performance Considerations:
$..(recursive descent) can be slow on large documents- Use specific paths when possible
- Filter early in the expression to reduce processing
- Consider the size of your JSON data
Still stuck?
- Copy a minimal JSON example that reproduces the issue
- Try the expression in this tool with your data
- Check the paths shown in the results
- Adjust your expression based on the actual structure