# JSONPath Extractor: pull fields out of JSON (`ucchiii/jsonpath-extractor`) Actor

Pulls fields out of nested JSON with JSONPath: $.a.b, \[\*], \[0], slices, .., filters like \[?(@.price > 10)]. Reads Apify datasets and JSON / NDJSON files, one clean row per record. Empty input = free demo.

- **URL**: https://apify.com/ucchiii/jsonpath-extractor.md
- **Developed by:** [Actor Factory](https://apify.com/ucchiii) (community)
- **Categories:** Developer tools, Automation, Integrations
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.91 / 1,000 output rows

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

**Pull the fields you need out of nested JSON, with JSONPath**

**Turns deeply nested JSON into flat rows, one row per record.** For anyone who has a scraper dataset or a JSON file where the value they want sits three levels down (`$.seller.address.city`), inside a list (`$.offers[0].price`), or somewhere in the middle of a long document (`$..email`), and who wants to get it out without writing code or a one-off script. Write a short map of `{"name": "path"}`, press Start, and download the result as CSV, JSON or Excel from the dataset. It works from the Console form: nothing to install, no code is run.

**Try it free: leave all inputs empty and press Start** (the demo is not charged and its rows carry `_demo: true`).
**$1.30 per 1,000 output rows**, charged per row ($0.0013 a row). Extracting from 20,000 records costs $26.00. The $5 monthly free credit covers about 3,800 output rows. Reading records is free. Rows with an error, records you choose to leave out, failed runs and the demo are not charged. No scraping, no API keys.

### Sample

Input records (a dataset or a JSON file), **Fields**:

```json
{
  "orderId": "$.id",
  "customer": "$.customer.name",
  "itemNames": "$.items[*].name",
  "over500": "$.items[?(@.price > 500)].name",
  "itemsTotal": "$.items[*].price.sum()",
  "coupon": "$.coupon.code"
}
```

| id | customer | items | coupon |
|---|---|---|---|
| A-1001 | Aiko Tanaka | Pen 120, Notebook 480, Tote bag 1500 | SPRING |
| A-1002 | Ben Carter | Pen 120 | (none) |
| A-1003 | Chloé Martin | (empty list) | WELCOME |

Output:

| orderId | customer | itemNames | over500 | itemsTotal | coupon |
|---|---|---|---|---|---|
| A-1001 | Aiko Tanaka | `["Pen", "Notebook", "Tote bag"]` | Tote bag | 2100 | SPRING |
| A-1002 | Ben Carter | Pen | null | 120 | null |
| A-1003 | Chloé Martin | null | null | null | WELCOME |

One match gives the value itself, several matches give a list, no match gives `null`.

### What you can write

- **Names and positions**: `$.a.b`, `$['a b']`, `$["dc:title"]`, `$.items[0]`, `$.items[-1]` (the last one).
- **Everything in a list or object**: `$.items[*].name`, `$.items.*`.
- **Slices and unions**: `$.items[1:3]`, `$.items[::2]`, `$.items[::-1]`, `$.items[0,2]`, `$['a','b']`.
- **Search at any depth**: `$..email` finds every `email` key wherever it is, `$..*` every value.
- **Filters**: `$.items[?(@.price > 10)]`, `[?(@.stock)]` (the field exists), `[?(!@.isbn)]`, `[?(@.a == 'x' && (@.b < 5 || @.c))]`. Compare with `== != < <= > >=`; text, numbers, `true`, `false` and `null` are different types and are never mixed up (`true` is not `1`). Inside a filter `@` is the item being tested and `$` is the record.
- **Filter functions**: `length(@.name) > 3`, `count(@.tags[*]) == 2`, `contains(@.tags, 'sale')`, `contains(@.title, 'Pro')`, `starts_with(@.sku, 'AB-')`, `ends_with(...)`, `value(@.tags[0])`.
- **Totals at the end of a path**: `.length()`, `.sum()`, `.min()`, `.max()`, `.avg()`, `.first()`, `.last()`. For example `$.items[*].price.sum()`. A single list match is used as the list (`$.items.length()` counts the items; `$.name.length()` is the length of the text).
- **Shortcut**: a path that starts with `.` or `[` (like `.user.name`) gets the `$` put in front for you.

Not supported, on purpose: regular expressions and arbitrary expressions or code. Paths are checked before anything is read, so a typo fails the run at once, free, with the position of the mistake.

### Fields in detail

Each entry of **Fields** is either a path text, or an object when you want more control:

```json
{
  "city": "$.address.city",
  "tags": {"path": "$.tags[*]", "multiple": "all"},
  "firstPhone": {"path": "$.phones[*]", "multiple": "first"},
  "country": {"path": "$.address.country", "default": "unknown"}
}
```

- **multiple**: `auto` (default: one match is the value, several are a list), `first` (only the first match), `all` (always a list).
- **default**: used when the path matches nothing (the field then counts as found).
- An empty list matched with `[*]` has no items, so it gives `null`; `$.tags` (without `[*]`) gives the list itself, even when it is empty.

### Where the records come from

- **Apify datasets** (resource picker, read permission only): every dataset item is a record.
- **JSON or NDJSON file URLs** (public links): a JSON list gives one record per item, a JSON file that is one object gives one record, an NDJSON file gives one record per line. Encoding is UTF-8.
- **Records path**: when the list you want is nested, for example a GeoJSON file or `{"data": {"items": [...]}}`, set **Records path** to `$.features` or `$.data.items`. Every item of that list becomes a record, and your field paths are written relative to one item.
- **How to split: Whole document**: each file (or line, or dataset item) is one record, so one path can look across the entire list. `$[?(@.rating > 8)].title` then collects all matching titles into a single row.
- Datasets and files can be mixed freely; they are read in the order given and come out as one table.

### If a field has no match

- **Set the field to null** (default). Rows with no match are still written and charged (a row of only `null` values is charged too). To avoid paying for such rows, use the options below.
- **Leave the whole record out**: a record where any field has no match is not written and not charged.
- **Keep the row and list the problem in `_errors`**: the row is written with the field `null` and `_errors` says which path matched nothing. This row is not charged. Filter on `_errors` to see what needs a look.

### Keep the original record

Switch on **Keep the original record** to copy the top-level fields of each input record into the row; your extracted fields come after them and win when a name is the same. Without it a row holds only the fields you extracted.

### Output

- **Dataset**: one row per record, in the input order, with your fields. Download as CSV, JSON, Excel and more from the Console.
- **`_errors`**: only on rows that had a problem (see above).
- **STATS** record (key-value store): records read per source, rows written and charged, per field how many records matched, had no match or several matches, up to 20 examples of problems, and a note for every path that matched nothing in any record (usually a typo or a wrong **Records path**).

### Limits (cannot be raised by input)

- **Up to 200,000 input records per run.** If there are more records than **Max input records**, the run stops without writing or charging rather than giving you a partial table. Split the data first.
- 20 datasets and files per run; 100 MB per file (a JSON file: 50 MB, because it has to be read whole; use NDJSON, one JSON value per line, for bigger files); 100 fields; a path can be 1,000 characters long.
- Each path has a safety limit on the work it may do for one record and on the number of values it may return (500,000). A record that hits the limit gets `null` for that field and an `_errors` entry; the other records are not affected.
- Source URLs must be public `http` or `https` links. Addresses on internal networks (localhost, private ranges, cloud metadata) are blocked, also after redirects. CSV and Excel files are not read.

### Pricing

Pay per event: **$1.30 per 1,000 output rows** (event `record`, $0.0013 per output row). Reading input records is free. Nothing is charged when the run fails, for the demo, for rows with `_errors`, or for records left out. Set a maximum charge per run: the Actor then writes only the first rows that fit the budget (never past it) and says so in the run summary. If the budget is lower than the price of one row, the run stops at once without charging.
On the Apify Free plan, the $5 of monthly platform credit covers about **3,800 rows** a month.

### Use cases

- Flatten a scraper dataset: `$.seller.address.city`, `$.offers[0].price`, `$.images[*].url` become plain columns
- Read API responses saved as JSON: pick out the list with **Records path**, then the fields of each item
- Find a key wherever it hides: `$..email`, `$..id`
- Get totals and counts per record: `$.items[*].price.sum()`, `$.reviews.length()`
- Collect all the values that pass a test across a whole document: a filter with **Whole document**
- Prepare flat, consistent columns for the next Actor in a workflow

### FAQ

**Does it change my source dataset?** No. It only reads it and writes a new dataset.
**Why is a field null?** The path matched nothing in that record. Check the spelling (names are case-sensitive) and look at the note in the run summary: it lists every path that matched nothing in any record.
**Why do I get a list for one field and a single value for another?** One match is returned as the value, several as a list. Set `"multiple": "all"` to always get a list, or `"first"` to always get one value.
**Why did a JSON file with one big object give only one row?** A single object is one record. Use **Records path** (for example `$.items`) to say where the list of records is.
**Can I use regular expressions?** No. Use `contains()`, `starts_with()` or `ends_with()` in a filter.
**Can I rename or calculate?** The output name is the key you choose in **Fields**. Totals and counts are available at the end of a path; there is no arithmetic between fields.

If this Actor saved you time, a rating on the Store helps others find it.

### More tools from the same developer

- [Flatten JSON to CSV](https://apify.com/ucchiii/flatten-json) — flatten nested JSON into flat rows with the separator you choose
- [Dataset Type Caster](https://apify.com/ucchiii/dataset-type-caster) — turn text columns into real numbers, booleans and dates: currencies, 1,200 vs 1.200, and Japanese era dates
- [JSON to CSV Converter](https://apify.com/ucchiii/json-to-csv) — turn nested JSON files or datasets into one flat CSV file
- [Dataset Column Profiler](https://apify.com/ucchiii/dataset-column-profiler) — profile every column of a dataset or CSV: types, missing values, distinct counts, top values and statistics
- [Filter CSV, JSON or Dataset Rows by Condition](https://apify.com/ucchiii/filter-rows) — keep only the rows of a CSV, JSON file or dataset that match simple conditions like country = US or price > 100

# Actor input Schema

## `datasetIds` (type: `array`):

Datasets to read (the 'defaultDatasetId' of a finished run). You can paste a dataset URL from Apify Console too. Each item of a dataset is one record. Several datasets and files are read in the order given and come out as one table. Up to 20 in total. Leave this and 'File URLs' empty to run a free demo on a built-in sample (not charged).

## `fileUrls` (type: `array`):

Public http(s) links to JSON or NDJSON files (up to 100 MB each; a JSON file up to 50 MB, use NDJSON for bigger files). A JSON file that is a list gives one record per item; a JSON file that is one object is one record (see 'Records path' and 'How to split'). Links to internal networks are blocked.

## `fields` (type: `object`):

The values to extract: an object of {"output name": "JSONPath"}. The path is applied to every record, with $ meaning the record. One match gives the value, several matches give a list, no match gives null (see 'If a field has no match'). For finer control use an object instead of the text: {"path": "$.tags\[\*]", "multiple": "auto|first|all", "default": "n/a"}: 'first' keeps only the first match, 'all' always gives a list, 'default' replaces a missing value. Paths are checked before anything is read: a mistake fails the run at once, free. Required unless you run the demo.

## `recordsPath` (type: `string`):

Optional. A JSONPath that finds the records inside each document, for when the list you want is nested, for example $.features or $.data.items. If it points to a list, every item of the list is a record; if it points to something else, that value is one record. Leave it empty to use the document as it is (a JSON file that is a list gives one record per item). Not used with 'Whole document'.

## `recordMode` (type: `string`):

'One record per item': a JSON file that is a list gives one row per item, a file that is one object gives one row, an NDJSON file gives one row per line, a dataset gives one row per item. 'Whole document': each JSON file, NDJSON line or dataset item is one record as a whole, so a path like $\[?(@.rating > 8)].title collects values across the entire list into one row. Default: one record per item.

## `onMissing` (type: `string`):

What happens when a path matches nothing in a record. 'null': the field is null (a field with a 'default' uses that value instead and counts as found). 'skip': a record where any field has no match is not written and not charged. 'error-row': the row is written with the field null and an '\_errors' list that says which path matched nothing; such a row is not charged. Default: null.

## `keepOriginal` (type: `boolean`):

Also copy the top-level fields of each input record into the output row (the extracted fields are added after them and win if a name is the same). A record that is not an object (a number, a list) is kept under the name 'value'. Default: off, so a row has only the fields you extracted.

## `maxInputRows` (type: `integer`):

Safety limit on the records read across all sources. If there are more records than this the run stops without writing or charging (it never gives you a partial table). Maximum and default: 200,000.

## Actor input object example

```json
{
  "fileUrls": [
    "https://raw.githubusercontent.com/vega/vega-datasets/main/data/burtin.json"
  ],
  "fields": {
    "bacteria": "$.Bacteria",
    "gram": "$.Gram_Staining",
    "penicillin": "$.Penicillin"
  },
  "recordMode": "auto",
  "onMissing": "null",
  "keepOriginal": false,
  "maxInputRows": 200000
}
```

# Actor output Schema

## `results` (type: `string`):

One row per record with the fields you asked for, in the input order. Rows with a problem carry \_errors. Download as CSV, JSON, Excel and more.

## `stats` (type: `string`):

Record STATS: records read per source, rows written and charged, per field how many records matched, had no match or several matches, and notes about paths that matched nothing.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "fileUrls": [
        "https://raw.githubusercontent.com/vega/vega-datasets/main/data/burtin.json"
    ],
    "fields": {
        "bacteria": "$.Bacteria",
        "gram": "$.Gram_Staining",
        "penicillin": "$.Penicillin"
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("ucchiii/jsonpath-extractor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "fileUrls": ["https://raw.githubusercontent.com/vega/vega-datasets/main/data/burtin.json"],
    "fields": {
        "bacteria": "$.Bacteria",
        "gram": "$.Gram_Staining",
        "penicillin": "$.Penicillin",
    },
}

# Run the Actor and wait for it to finish
run = client.actor("ucchiii/jsonpath-extractor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "fileUrls": [
    "https://raw.githubusercontent.com/vega/vega-datasets/main/data/burtin.json"
  ],
  "fields": {
    "bacteria": "$.Bacteria",
    "gram": "$.Gram_Staining",
    "penicillin": "$.Penicillin"
  }
}' |
apify call ucchiii/jsonpath-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,ucchiii/jsonpath-extractor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/Hm0Ts6vjlwLndMJZd/builds/hBEFKpg7u50ekhaZQ/openapi.json
