# Quick Question JSON API format

**URL:** <https://discuss.jsonapi.org/t/quick-question-json-api-format/2572>\
**Category:** Uncategorized\
**Created:** [December 3, 2022, 11:50am UTC](https://discuss.jsonapi.org/t/quick-question-json-api-format/2572 "2022-12-03T11:50:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariam](https://avatars.discourse-cdn.com/v4/letter/m/b9e5f3/32.png) [@mariam](https://discuss.jsonapi.org/u/mariam)\
**Post date:** [December 3, 2022, 11:50am UTC](https://discuss.jsonapi.org/t/quick-question-json-api-format/2572/1 "2022-12-03T11:50:47Z")

</div>

Is this format is a correct format based on JSONAPI specs. Can we have an array as attributes?

```auto
{
  "meta": {
  },
  "links": {
    "self": ""
  },
  "jsonapi": {
    "version": "",
    "meta": {
    }
  },
  "data": {
    "type": "typeof(class)",
    "id": "string",
    "attributes": [
      {
        "item1": "Value1",
        "item2": "Value2",
        "item3": "Value3"
      }
    ],
    "links": {
      "self": ""
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![jelhan](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/jelhan/32/822_2.png) [@jelhan](https://discuss.jsonapi.org/u/jelhan)\
**Post date:** [December 6, 2022, 9:11pm UTC](https://discuss.jsonapi.org/t/quick-question-json-api-format/2572/2 "2022-12-06T21:11:56Z")

</div>

No. This is not a valid accordingly to JSON:API specification.

> 7.2.2.1 Attributes
> 
> The value of the `attributes` key **MUST** be an object (an “attributes object”). Members of the attributes object (“attributes”) represent information about the [resource object](https://jsonapi.org/format/#document-resource-objects) in which it’s defined.
> 
> Attributes may contain any valid JSON value, including complex data structures involving JSON objects and arrays.
> 
> [JSON:API — Latest Specification (v1.1)](https://jsonapi.org/format/#document-resource-object-attributes)

The value of an attribute may be complex data structure like an array. This would be valid:

```json
{
  "type": "person",
  "id": "27",
  "attributes": {
    "interests": ["football", "politics", "history"]
  }
}

```

I would recommend being careful using objects and arrays as attribute values. Often it is better modeled as a relationship to another resource. As illustrated by the example I have included above.
