OhMyApps
Back to Blog
Tools Developer JSON JSONPath Tutorial

JSONPath Tester: Query and Extract Data from JSON

4 min read By OhMyApps

JSONPath is a query language for JSON, similar to how XPath works for XML. It lets you extract specific values from complex JSON structures using simple path expressions — no code required.

What is JSONPath?

JSONPath was introduced by Stefan Goessner as a way to navigate JSON data structures. Given a complex JSON document, a JSONPath expression pinpoints exactly the data you need.

Think of it like a file path for JSON:

$.store.book[0].title
  |    |     |    |
  $    |     |    └── Get the "title" field
  |    |     └── First item in the array
  |    └── Navigate to "book"
  └── Start at root

JSONPath Syntax

Basic Navigation

ExpressionDescriptionExample
$Root object$ returns the entire document
.keyChild access$.name gets the “name” field
[0]Array index$.items[0] gets the first item
[*]All items$.items[*] gets every item

Accessing Nested Data

For this JSON:

{
  "store": {
    "book": [
      { "title": "Moby Dick", "price": 8.99 },
      { "title": "The Lord of the Rings", "price": 22.99 }
    ],
    "bicycle": { "color": "red", "price": 19.95 }
  }
}
ExpressionResult
$.store.bicycle.color"red"
$.store.book[0].title"Moby Dick"
$.store.book[*].title["Moby Dick", "The Lord of the Rings"]
$.store.book[*].price[8.99, 22.99]
$.store.book[1]{ "title": "The Lord of the Rings", "price": 22.99 }

Array Indexing

[0]     → First item
[1]     → Second item
[-1]    → Last item
[-2]    → Second to last item
[*]     → All items

Common Use Cases

API Response Parsing

When working with REST APIs, you often need specific fields from deeply nested responses:

{
  "response": {
    "users": [
      { "id": 1, "profile": { "name": "Alice" } },
      { "id": 2, "profile": { "name": "Bob" } }
    ]
  }
}

Expression: $.response.users[*].profile.name["Alice", "Bob"]

Configuration Extraction

Pull specific values from complex configuration files:

{
  "environments": {
    "production": {
      "database": { "host": "prod-db.example.com", "port": 5432 }
    }
  }
}

Expression: $.environments.production.database.host"prod-db.example.com"

Testing and Validation

Use JSONPath to verify API responses contain expected data:

// In test frameworks
expect(jsonPath(response, '$.data.status')).toBe('active');
expect(jsonPath(response, '$.data.items[*].id')).toHaveLength(3);

Data Transformation

Extract specific fields before feeding data into another system:

Input: Complex API response with 50+ fields
Path: $.results[*].{id, name, email}
Output: Clean array with just the fields you need

How to Use Our JSONPath Tester

  1. Enter a JSONPath expression in the path input field
  2. Paste your JSON data in the left panel (or use the sample data)
  3. View the matching results instantly in the right panel
  4. Use quick expression buttons to try common patterns
  5. Check the match count to see how many results were found

Quick Start

Click the Sample button to load example data, then try these expressions:

  • $ — See the entire document
  • $.store.book[*].author — Get all book authors
  • $.store.book[0] — Get the first book
  • $.store.book[*].price — Get all book prices
  • $.store.bicycle — Get the bicycle object

Tips

  • Expressions must start with $ (the root)
  • Use . notation for named properties
  • Use [index] for specific array items
  • Use [*] to iterate over all array items
  • The tool evaluates in real-time as you type

JSONPath in Different Languages

JSONPath is available in most programming languages:

  • JavaScript: jsonpath, jsonpath-plus
  • Python: jsonpath-ng, jsonpath-rw
  • Java: Jayway JsonPath
  • Go: github.com/PaesslerAG/jsonpath
  • PHP: flow/jsonpath

Frequently Asked Questions

What’s the difference between JSONPath and jq? Both query JSON, but jq is a command-line tool with its own syntax (.[].name), while JSONPath uses XPath-inspired syntax ($[*].name) and is available as a library in most languages.

Can JSONPath modify data? No, JSONPath is read-only — it queries and extracts data but doesn’t modify the source. For transformations, use jq or write code.

Are JSONPath expressions case-sensitive? Yes. $.Name and $.name refer to different fields. JSON keys are case-sensitive.


Try our free JSONPath Tester to query and extract data from any JSON document instantly.

Try Ghost Image Hub

The Chrome extension that makes managing your Ghost blog images a breeze.

Learn More