---
title: "Create a JSONPath document extractor"
slug: "create-a-jsonpath-document-extractor"
abstract: "Use a JSONPath expression to extract attribute values when you create a document extractor for an API crawler source in Sitecore Search. Use tags, rules, and URL matching."
---
# Create a JSONPath document extractor

Create an XPath document extractor when you want to use an XPath expression to extract attribute values in a Sitecore Search source.

To create a JSONPath document extractor matching URLs with a JavaScript function:

1. On the menu bar, click **Sources**.
2. Select the source you created.
3. On the **Source Settings** page, next to **Document Extractors**, click **Edit** ![pencil_grey.png](https://doc.sitecore.com/api/markdown-image/search/en/users/search-user-guide/images/pencil_grey.png).
4. To create a [document extractor](https://doc.sitecore.com/search/en/users/search-user-guide/index-items/additional-configurations-and-settings/configuring-document-extractors.html "Configuring document extractors"), on the **Document Extractors** page:
    - In the **Name** field, enter a meaningful name for the extractor.

        For example, enter *Sitecore cloud*.

    - In the **Extractor Type** drop-down menu, click **JSONPath**.
    - Optionally, to ensure that this extractor's logic only applies to [URLs that match](https://doc.sitecore.com/search/en/users/search-user-guide/index-items/additional-configurations-and-settings/configuring-document-extractors.html#UUID-bf3b8a27-e317-f7e3-9fe5-88d81969a12c_section-idm4597072673881633832915676016 "URLs to match") a certain pattern, configure **URLs to Match**. To do this, in the **URLs To Match** field, click ![Plus_add__grey.png](https://doc.sitecore.com/api/markdown-image/search/en/users/search-user-guide/images/Plus_add__grey.png) **Add Matcher**, select the **TYPE** of expression you want to use, and enter the **VALUE** of that expression.

        For example, click **JS** in the **TYPE** drop-down menu and enter the following expression to use JavaScript to ensure that the extractor only extracts attributes from API endpoints whose response has a value for `body.data.item.rendered`.

        ```javascript
        function match(request, response) {
          return response.body.data.item.rendered != null &&
          response.body.data.item.rendered.sitecore.route.placeholders['headless-main'].length > 0;
        }
        ```

5. In the **Taggers** section, click **Add Tagger** . Then, in the tag editor, select a [tag](https://doc.sitecore.com/search/en/users/search-user-guide/index-items/additional-configurations-and-settings/crawler-tags.html "Crawler tags") in the **Tag** drop-down menu. For example, select *content*.

    > [!note]
    > In a document extractor, you can create multiple taggers where each is linked to a unique tag. This way each tagger:
    >
    > -   Generates a set of index documents.
    >
    > -   Can have multiple rules such that each rule defines the extraction logic of one attribute.
    >
    >
    > For example, one tagger with five rules yields *one* set of documents each with *five* attributes.
    >
    > Three taggers with one rule each yields *three* sets of documents each with *one* attribute.

6. In the tag editor, enter the following details to extract an attribute:
    - In the **Attribute** drop-down menu, click the attribute you want to configure.

        For example, click **Description**.

    - In the **Value type** drop-down menu, choose whether you want the attribute value to be a fixed value or an expression.

        For example, click **Expressions**.

    - In the **EXPRESSION** field, enter a JSONPath expression that results in the attribute value.

        For example, to get the value of *description* from the of the `..placeholders['headless-main']..fields.Description` key, enter

        ```shell
        ..placeholders['headless-main']..fields.Description.value
        ```

7. Optionally, to configure more than one way to get an attribute value, click ![Plus_add__grey.png](https://doc.sitecore.com/api/markdown-image/search/en/users/search-user-guide/images/Plus_add__grey.png) **Add Selector**. Then, in the **Expression** field of the second selector, enter the JSONPath expression that results in the attribute value.

    For example, as a second option, you want to get the value of *description* from the `..placeholders['headless-main']..fields.Text` tag. To get this, enter the following JSONPath expression:

    ```shell
    ..placeholders['headless-main']..fields.Text.value
    ```

    > [!note]
    > When there are multiple selectors, Search runs them in chronological order and stops when it arrives at an expression that gives a result.

8. To configure how to extract other attributes, click **Add Rule** ![Plus_add__grey.png](https://doc.sitecore.com/api/markdown-image/search/en/users/search-user-guide/images/Plus_add__grey.png) and repeat steps 5 and 6.

    For example, now that you've configured how to extract the *description* attribute, you can configure how to extract the *title*, *subtitle*, and *image* attributes.

9. In the tag editor, click **Save**.
10. (Optional) To extract attributes for another tag, click ![Plus_add__grey.png](https://doc.sitecore.com/api/markdown-image/search/en/users/search-user-guide/images/Plus_add__grey.png) **Add Tagger**, and in the **Tag** drop-down menu, click a tag and repeat Steps 5 through 8.
11. On the **Document Extractors** page, click **Save**.