# Should all the fields be strings?

**URL:** https://discuss.jsonapi.org/t/should-all-the-fields-be-strings/1225
**Category:** Uncategorized
**Created:** [March 6, 2018, 4:01pm UTC](https://discuss.jsonapi.org/t/should-all-the-fields-be-strings/1225 "2018-03-06T16:01:05Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![e21524e3](https://avatars.discourse-cdn.com/v4/letter/e/d78d45/32.png) [@e21524e3](https://discuss.jsonapi.org/u/e21524e3)
#### Post date: [March 6, 2018, 4:01pm UTC](https://discuss.jsonapi.org/t/should-all-the-fields-be-strings/1225/1 "2018-03-06T16:01:05Z")

</div>

I cannot find any reference to this in the documentation. Should the client send every field in a string form?  
For instance, if an attribute of a resource is `age`, should I send `"age": 23` or `"age": "23"`?

---

<div class="post-metadata">

### Author: ![steveklabnik](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.jsonapi.org/steveklabnik/32/2_2.png) [@steveklabnik](https://discuss.jsonapi.org/u/steveklabnik)
#### Post date: [March 6, 2018, 4:49pm UTC](https://discuss.jsonapi.org/t/should-all-the-fields-be-strings/1225/2 "2018-03-06T16:49:07Z")

</div>

[http://jsonapi.org/format/#document-resource-object-attributes](http://jsonapi.org/format/#document-resource-object-attributes)

> Attributes may contain any valid JSON value.

---

<div class="post-metadata">

### Author: ![e21524e3](https://avatars.discourse-cdn.com/v4/letter/e/d78d45/32.png) [@e21524e3](https://discuss.jsonapi.org/u/e21524e3)
#### Post date: [March 6, 2018, 4:58pm UTC](https://discuss.jsonapi.org/t/should-all-the-fields-be-strings/1225/3 "2018-03-06T16:58:22Z")

</div>

Ahh here it is! thank you very much!

@steveklabnik If you don’t mind, I have a further question on this… Say I have an `integer` column `age` in a database. Do you think the server should then treat both integers (eg `23`) as well as numeric strings (`"23"`) the same, so that clients could transparently send data both in numeric and string values? Or instead the server should make a choice?

---

<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: [March 7, 2018, 1:10pm UTC](https://discuss.jsonapi.org/t/should-all-the-fields-be-strings/1225/4 "2018-03-07T13:10:00Z")

</div>

Inferred types are evil. Be a good neighbor and be explicit! Future you will _love_ you for it.

---

<div class="post-metadata">

### Author: ![e21524e3](https://avatars.discourse-cdn.com/v4/letter/e/d78d45/32.png) [@e21524e3](https://discuss.jsonapi.org/u/e21524e3)
#### Post date: [March 7, 2018, 1:55pm UTC](https://discuss.jsonapi.org/t/should-all-the-fields-be-strings/1225/5 "2018-03-07T13:55:42Z")

</div>

@michaelhibay thank you! So, are you for not accepting data (example, in an API, respond with an error) if I am expecting an integer and instead a string is passed?  
In particular, in this case, I would refer to [error processing](http://jsonapi.org/format/#errors-processing) and respond with `4xx`.

---

<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: [March 7, 2018, 3:05pm UTC](https://discuss.jsonapi.org/t/should-all-the-fields-be-strings/1225/6 "2018-03-07T15:05:51Z")

</div>

I think you should be very explicit about the contract and options you plan to support with respect to the data types you accept in your messages. If you aren’t explicit in schemas, you add ambiguity, requiring devs to look through your documentation, and if you aren’t there then you have a big problem. Strings are evil, once you start adding odd formats and can get really crazy stuff to happen.
