> For the complete documentation index, see [llms.txt](https://docs.pinot.apache.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pinot.apache.org/functions/json/jsonpathlong.md).

# JSONPATHLONG

This section contains reference documentation for the JSONPATHLONG function.

Extracts the **Long** value from `jsonField` based on `'jsonPath'`, use optional `defaultValue`for null or parsing error. This function can only be used in an [ingestion transformation function](/build-with-pinot/ingestion/transformations-and-aggregations/ingestion-level-transformations.md).

## Signature

> JSONPATHLONG(jsonField, 'jsonPath', \[defaultValue])

| Arguments    | Description                                                                                            |
| ------------ | ------------------------------------------------------------------------------------------------------ |
| `jsonField`  | An **Identifier**/**Expression** contains JSON documents.                                              |
| `'jsonPath'` | Follows [JsonPath Syntax](https://goessner.net/articles/JsonPath/) to read values from JSON documents. |

{% hint style="warning" %}
**`'jsonPath'`**\` is a literal. Pinot uses single quotes to distinguish them from **identifiers**.\
\
You can use the [Jayway JsonPath Evaluator Tool](https://jsonpath.herokuapp.com/) to test JSON expressions before you import any data.
{% endhint %}

## Usage Examples

The usage examples are based on extracting fields from the following JSON document:

```json
{
  "data": {
    "name": "Pete",
    "age": 24,
    "subjects": [
      {
        "name": "maths",
        "homework_grades": [80, 85, 90, 95, 100],
        "grade": "A",
        "score": 90
      },
      {
        "name": "english",
        "homework_grades": [60, 65, 70, 85, 90],
        "grade": "B",
        "score": 70
      }
    ]
  }
}
```

| Expression                    | Value |
| ----------------------------- | ----- |
| `JSONPATHLONG(data, '$.age')` | `24`  |

This function can be used in the [table config](/reference/configuration-reference/table.md) to extract the `age` property into the `age` column, as described below:

```json
{
   "tableConfig":{
      "ingestionConfig":{
         "transformConfigs":[
            {
               "columnName":"age",
               "transformFunction":"JSONPATHLONG(data, '$.age')"
            }
         ]
      }
   }
}
```

## Value conversion

`JSONPATHLONG` converts a matched value to a long as follows:

| Matched value                     | Result                                  |
| --------------------------------- | --------------------------------------- |
| Number                            | The value's long representation         |
| Boolean                           | `true` becomes `1`; `false` becomes `0` |
| `TIMESTAMP` in materialized input | Epoch milliseconds                      |
| `DATE` in materialized input      | Days since the Unix epoch               |
| `TIME` in materialized input      | Milliseconds since midnight             |

The `TIMESTAMP`, `DATE`, and `TIME` conversions apply when an extractor has already materialized the input as a record object instead of JSON text. Missing or null values, non-numeric values, and conversion errors return `defaultValue` when it is supplied.

## Fast and first-match variants

### JSONPATHLONGFORY (experimental)

> JSONPATHLONGFORY(jsonField, 'jsonPath', \[defaultValue])

`JSONPATHLONGFORY` evaluates eligible simple scalar paths with Apache Fory and falls back to `JSONPATHLONG` for unsupported inputs or when Fory is unavailable. The standard Pinot distribution does not ship Fory; the accelerated path requires `org.apache.fory:fory-json:1.6.0` and `fory-core` on the ingestion application's classpath. This experimental function may change or be removed.

Use the opt-in variants below when the path is a **simple linear path**: `$` followed only by `.name`, `['literal.key']`, or `[0]` segments. For more complex JsonPath features such as wildcards, deep scan (`..`), filters, unions, slices, negative indexes, or a bare `$`, Pinot falls back to the existing `JSONPATHLONG` behavior.

Like `JSONPATHLONG`, both variants are intended for [ingestion transformation functions](/build-with-pinot/ingestion/transformations-and-aggregations/ingestion-level-transformations.md).

### JSONPATHLONGFAST

> JSONPATHLONGFAST(jsonField, 'jsonPath', \[defaultValue])

`JSONPATHLONGFAST` resolves supported paths in a single forward pass over the JSON text instead of building the full Jayway DOM first. It keeps the same result as `JSONPATHLONG`, including the same `defaultValue` handling, and falls back to the existing implementation when the path is not a simple linear path or the input is not a JSON object or array.

Use `JSONPATHLONGFAST` when you want lower ingestion CPU cost without changing semantics.

### JSONPATHLONGFIRSTMATCH

> JSONPATHLONGFIRSTMATCH(jsonField, 'jsonPath', \[defaultValue])

`JSONPATHLONGFIRSTMATCH` uses the same streaming fast path but stops as soon as the addressed field is found. This is usually the fastest option when the field appears early in the JSON document, but it changes behavior for undefined or corrupt input:

* Duplicate keys resolve to the **first** occurrence instead of the last one.
* A document malformed strictly after the addressed field can still return the extracted value.

Use `JSONPATHLONGFIRSTMATCH` only when the upstream JSON is well-formed and duplicate-free.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pinot.apache.org/functions/json/jsonpathlong.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
