# Sparse Fieldsets and Relations (error in example?)

**URL:** https://discuss.jsonapi.org/t/sparse-fieldsets-and-relations-error-in-example/1258
**Category:** Uncategorized
**Created:** [April 9, 2018, 7:09am UTC](https://discuss.jsonapi.org/t/sparse-fieldsets-and-relations-error-in-example/1258 "2018-04-09T07:09:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![marceloverdijk](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/marceloverdijk/32/521_2.png) [@marceloverdijk](https://discuss.jsonapi.org/u/marceloverdijk)
#### Post date: [April 9, 2018, 7:09am UTC](https://discuss.jsonapi.org/t/sparse-fieldsets-and-relations-error-in-example/1258/1 "2018-04-09T07:09:00Z")

</div>

As per the examples `GET /articles?include=author&fields[articles]=title,body&fields[people]=name` returns:

```
{
  "data": [{
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "JSON API paints my bikeshed!",
      "body": "The shortest article. Ever."
    }
  }],
  "included": [
    {
      "type": "people",
      "id": "42",
      "attributes": {
        "name": "John"
      }
    }
  ]
}

```

Is it correct that the author is included here?

I’m asking as the author was not in `fields[articles]=title,body`.  
Note the relationship was not included (as expected) but what is the use of getting the author included?

It feels like an error in the example…

---

<div class="post-metadata">

### Author: ![michaelhibay](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/michaelhibay/32/405_2.png) [@michaelhibay](https://discuss.jsonapi.org/u/michaelhibay)
#### Post date: [April 9, 2018, 3:19pm UTC](https://discuss.jsonapi.org/t/sparse-fieldsets-and-relations-error-in-example/1258/2 "2018-04-09T15:19:39Z")

</div>

`author` is the name of the _relationship_ `article -> people`, but the resource type is `people`.

The query string starts out with `include=author&...`. I don’t think it’s explicitly stated, but the most sensible parsing order of the different data shaping capabilities goes `include -> filtering / sorting / pagination -> sparse fieldsets`.

The relationship, and resource identifier object data is required for processing and full linkage for the response documents, sparse field sets just provides a means to limit the representation clutter to a minimum set _in addition_ to the requirements of the format and provided parameters.

In other words, I look at sparse field sets as a representation post-processor. It isn’t required to be implemented this way of course, but that is the order of precedence I see in the specification.

---

<div class="post-metadata">

### Author: ![marceloverdijk](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/marceloverdijk/32/521_2.png) [@marceloverdijk](https://discuss.jsonapi.org/u/marceloverdijk)
#### Post date: [April 9, 2018, 3:39pm UTC](https://discuss.jsonapi.org/t/sparse-fieldsets-and-relations-error-in-example/1258/3 "2018-04-09T15:39:08Z")

</div>

Yes, `author` is the relationship name.  
As the `author` is not included in the fields of the `articles` resource query param (`fields[articles]=title,body`) the relationship is not included in the response.  
But isn’t it strange that it _is_ in the `included`?

But as you explain it, is also a possible interpretation of the spec.

---

<div class="post-metadata">

### Author: ![lode](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/lode/32/592_2.png) [@lode](https://discuss.jsonapi.org/u/lode)
#### Post date: [March 12, 2021, 12:00pm UTC](https://discuss.jsonapi.org/t/sparse-fieldsets-and-relations-error-in-example/1258/4 "2021-03-12T12:00:59Z")

</div>

[The spec](https://jsonapi.org/format/1.1/#fetching-includes) states (emphasis mine):

> Note: Because [compound documents](https://jsonapi.org/format/1.1/#document-compound-documents) require full linkage ( **except when relationship linkage is excluded by sparse fieldsets** ), intermediate resources in a multi-part path must be returned along with the leaf nodes. For example, a response to a request for `comments.author` should include `comments` as well as the `author` of each of those `comments` .

Thus this example seems correct. It is a bit of a weird request though, it might be nicer to use `GET /articles?include=author&fields[articles]=title,body,author&fields[people]=name` and have the relationship linkage in the response as well.
