# How to define the path for selecting JSON objects

Coupler.io lets you connect to almost any API that returns JSON data.

In most cases, when you fetch a list of objects, a JSON array is returned.

{% hint style="info" %}
A JSON array is an ordered sequence of values.
{% endhint %}

A JSON array can appear at different levels in the response. Depending on where it appears, you need to set the **Path** parameter accordingly. Below are the most common cases and the right settings to use in Coupler.io.

{% hint style="info" %}
To check the JSON array structure returned by your API, use the API documentation and an API client such as [Postman](https://www.postman.com/).
{% endhint %}

#### JSON array at the root level

This is the simplest setup. For example, the API response looks like this:

```json
[
   {
      "id":"76013791",
      "customerName":"JOHN DOE",
      "total":1409.62
    }
]
```

Leave the **Path** parameter empty in Coupler.io:

![](https://s3.amazonaws.com/helpscout.net/docs/assets/57fbf3029033600277a688ab/images/620a9d012130e5169468720d/file-NAn5goJ0yK.png)

You will get the following result in the destination:

![](https://s3.amazonaws.com/helpscout.net/docs/assets/57fbf3029033600277a688ab/images/620aa1e368cd260cc2d3aff8/file-UaJZ2eXqa3.png)

#### JSON array inside a JSON object

Another common case is when the list of objects is placed inside a JSON object with one key:

```json
{
   "orders":[
      {
         "id":"76013791",
         "customerName":"JOHN DOE",
         "total":1409.62
      }
   ]
}
```

If you leave the **Path** parameter empty in Coupler.io, the result headers will be named like this: `orders.id`, `orders.customerName`, `orders.total`.

![](https://s3.amazonaws.com/helpscout.net/docs/assets/57fbf3029033600277a688ab/images/620aa30f2130e51694687230/file-SY1yJrnMvP.png)

To get clean header names, use the key that appears before **:\[** in the JSON response as the **Path** value. In this example, set **Path** to `orders`:

![](https://s3.amazonaws.com/helpscout.net/docs/assets/57fbf3029033600277a688ab/images/620a9f6b68cd260cc2d3afea/file-v1IsYjBs0H.png)

You will get the following result in the destination:

![](https://s3.amazonaws.com/helpscout.net/docs/assets/57fbf3029033600277a688ab/images/620aa1e368cd260cc2d3aff8/file-UaJZ2eXqa3.png)

#### JSON array inside nested JSON objects

This is similar to the previous case, but the array is nested inside several objects:

```json
{
   "results":{
      "orders":[
         {
            "id":"76013791",
            "customerName":"JOHN DOE",
            "total":1409.62
         }
      ]
   }
}
```

If you leave the **Path** parameter empty in Coupler.io, the result headers will look like this:

![](https://s3.amazonaws.com/helpscout.net/docs/assets/57fbf3029033600277a688ab/images/620aa39868cd260cc2d3b007/file-OzwxterQUG.png)

To get clean header names, use the full nested key path that appears before **:\[** in the JSON response. In this example, set **Path** to `results.orders`:

![](https://s3.amazonaws.com/helpscout.net/docs/assets/57fbf3029033600277a688ab/images/620aa3e868cd260cc2d3b00b/file-WtNM6EeqIF.png)

You will get the following result in the destination:

![](https://s3.amazonaws.com/helpscout.net/docs/assets/57fbf3029033600277a688ab/images/620aa3f7025ca67522c7b08d/file-rlLqvLoXyw.png)

#### JSON array with a nested JSON array

Some APIs return the list you need inside another list. For example, a products list can sit inside an orders list:

```json
{
   "results":{
      "orders":[
         {
            "id":"76013791",
            "customerName":"JOHN DOE",
            "total":1409.62,
            "products":[
               {
                  "id":"prod1",
                  "name":"T-Shirt",
                  "size":"M",
                  "quantity":"3",
                  "total":54.99
               }
            ]
         }
      ]
   }
}
```

If you leave the **Path** parameter empty in Coupler.io, you will get the following result, with all the data in a single row:

![](https://s3.amazonaws.com/helpscout.net/docs/assets/57fbf3029033600277a688ab/images/620aa60e39e5d05141b698b4/file-RVawrFNtgr.png)

As you can see in the screenshot above, the number `0` appears after `results.orders`. It is the index of the first order in the `orders` array. The same applies to `results.orders.0.products`: the `0` there is the index of the product in the `products` array.

{% hint style="info" %}
A JSON array is zero-indexed, so the first item has index `0`. [Read more](https://www.microfocus.com/documentation/silk-performer/205/en/silkperformer-205-webhelp-en/GUID-0847DE13-2A2F-44F2-A6E7-214CD703BF84.html).
{% endhint %}

To extract orders with their products, use `results.orders` as the **Path** value:

![](https://s3.amazonaws.com/helpscout.net/docs/assets/57fbf3029033600277a688ab/images/620aa676025ca67522c7b09c/file-ahyhwKYM0q.png)

You will get the order data in the destination, plus one row per product in each order. In this example, the order data shown in yellow will be duplicated.

{% hint style="info" %}
**Note:** In the image below, the second product, `prod2`, was added for clarity. It was not included in the original JSON above.

<img src="https://s3.amazonaws.com/helpscout.net/docs/assets/57fbf3029033600277a688ab/images/620aa6cad86136157d9a4127/file-jaL5JPWXJU.png" alt="" data-size="original">
{% endhint %}

To extract only the products for a specific order, use `results.orders.0.products` as the **Path** value. In this example, it points to the first order because there is only one:

![](https://s3.amazonaws.com/helpscout.net/docs/assets/57fbf3029033600277a688ab/images/620aa75939e5d05141b698bd/file-F9eWlqNSkX.png)

{% hint style="info" %}
**Note:** The first element in an array has index `0`, the second has index `1`, and so on.
{% endhint %}

Only the product data will be saved to the destination:

![](https://s3.amazonaws.com/helpscout.net/docs/assets/57fbf3029033600277a688ab/images/620aa77568cd260cc2d3b027/file-cUN6F8J3em.png)

{% hint style="warning" icon="hand-wave" %}
If you run into issues while defining the **Path** value, contact our Support Team at **<contact@coupler.io>**.
{% endhint %}
