# Inclusion of related resources: what to do with empty results?

**URL:** https://discuss.jsonapi.org/t/inclusion-of-related-resources-what-to-do-with-empty-results/2191
**Category:** Uncategorized
**Created:** [April 5, 2021, 10:28pm UTC](https://discuss.jsonapi.org/t/inclusion-of-related-resources-what-to-do-with-empty-results/2191 "2021-04-05T22:28:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![claudenirmf](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/claudenirmf/32/714_2.png) [@claudenirmf](https://discuss.jsonapi.org/u/claudenirmf)
#### Post date: [April 5, 2021, 10:28pm UTC](https://discuss.jsonapi.org/t/inclusion-of-related-resources-what-to-do-with-empty-results/2191/1 "2021-04-05T22:28:47Z")

</div>

Let’s consider a valid and supported request to include related resources, for example, `GET /posts?include=comments`. Now, if we consider the case where no post has comments, what is the best (or the recommended) approach:

1. Respond with included set to an empty array:

```json
{
  "data": [<some posts here>],
  "included": []
}

```

1. Respond with included set to null:

```json
{
  "data": [<some posts here>],
  "included": null
}

```

1. Respond without a included field:

```json
{
  "data": [<some posts here>]
}

```

I did not find a clear answer by checking the specification, the forum, and the JSON Schema, so I created this post.

I believe option (1) to be the best. Also, option (3) seems to be the worst because the client may be lead into believe that the “include” query was ignored.

---

<div class="post-metadata">

### Author: ![prathe](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/prathe/32/643_2.png) [@prathe](https://discuss.jsonapi.org/u/prathe)
#### Post date: [April 8, 2021, 2:04pm UTC](https://discuss.jsonapi.org/t/inclusion-of-related-resources-what-to-do-with-empty-results/2191/2 "2021-04-08T14:04:36Z")

</div>

`null` would not produce a valid response json according to the schema: [JSON:API — Frequently Asked Questions](https://jsonapi.org/faq/#is-there-a-json-schema-describing-json-api)

```
{
  "data": [<some posts here>],
  "included": null
}

```

I think that an empty array for `included` when inclusion is explicit in the request is more predictable and more friendly to the consumer of the API. Omission of the `included` keyword when requested may generate confusion.

---

<div class="post-metadata">

### Author: ![fdrake](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/fdrake/32/654_2.png) [@fdrake](https://discuss.jsonapi.org/u/fdrake)
#### Post date: [April 8, 2021, 7:39pm UTC](https://discuss.jsonapi.org/t/inclusion-of-related-resources-what-to-do-with-empty-results/2191/3 "2021-04-08T19:39:53Z")

</div>

In fact, while JSON:API 1.0 allows the `included` member to be omitted if the list is empty, JSON:API 1.1 specifically requires it to be present if an `include` query parameter is sent.

So returning an empty list for `included` is the best approach if `include` was specified and there’s nothing to include.

(Assuming a non-error response.)

-Fred
