# How to return an object in json to be a hash and not a string hash

**URL:** https://discourse.dry-rb.org/t/how-to-return-an-object-in-json-to-be-a-hash-and-not-a-string-hash/512
**Category:** dry-types
**Created:** [March 15, 2018, 6:56am UTC](https://discourse.dry-rb.org/t/how-to-return-an-object-in-json-to-be-a-hash-and-not-a-string-hash/512 "2018-03-15T06:56:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![cyb-ahmadh](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@cyb-ahmadh](https://discourse.dry-rb.org/u/cyb-ahmadh)
#### Post date: [March 15, 2018, 6:56am UTC](https://discourse.dry-rb.org/t/how-to-return-an-object-in-json-to-be-a-hash-and-not-a-string-hash/512/1 "2018-03-15T06:56:01Z")

</div>

Below is the api response:

```
{
    "total": 59198,
    "products": [
        {
            "id": "23423",
            "name": {
                "German": "s.Oliver BLACK LABE - Damen, Weiß, Größe 44"
            },
            "brand": "s.Oliver BLACK LABEL",
            "image_url": "https://some_url.com",
            "category": "Shirts & Tops"
        },...
   ]
}

```

and i’m using `dry-struct` to convert the `response` to ruby objects. For that below is the class:

```
class SomeService < Dry::Struct
    include Dry::Types.module

    attribute 'id', String
    attribute 'brand', String
    attribute 'image_url', String
    attribute 'category', String
    attribute 'name', Strict::hash
 end

```

Notice the `attribute name`. The name attribute in the response is `json` and for that i’m using `Strict::Hash` to convert the json in ruby hash. I’m not sure about it.

Still the response is like this:

```
{
        "brand": "s.Oliver BLACK LABEL",
        "name": "{\"German\"=>\"s.Oliver BLACK LABEL - Damen, Weiß, Größe 44\"}"
}

```

Let me know what am i doing wrong ?

---

<div class="post-metadata">

### Author: ![cyb-ahmadh](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@cyb-ahmadh](https://discourse.dry-rb.org/u/cyb-ahmadh)
#### Post date: [March 15, 2018, 2:14pm UTC](https://discourse.dry-rb.org/t/how-to-return-an-object-in-json-to-be-a-hash-and-not-a-string-hash/512/2 "2018-03-15T14:14:22Z")

</div>

I’ve resolved this issue. The problem was not with the dry-struct but the graphql types.

---

<div class="post-metadata">

### Author: ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)
#### Post date: [March 16, 2018, 10:20am UTC](https://discourse.dry-rb.org/t/how-to-return-an-object-in-json-to-be-a-hash-and-not-a-string-hash/512/3 "2018-03-16T10:20:00Z")

</div>

I recommend using your own `Types` module where you include built-in types, instead of including them in the struct classes, they have same names as some core classes like `String`, `Hash` etc. and you really want to have name namespaced.

---

<div class="post-metadata">

### Author: ![cyb-ahmadh](https://avatars.discourse-cdn.com/v4/letter/c/df788c/32.png) [@cyb-ahmadh](https://discourse.dry-rb.org/u/cyb-ahmadh)
#### Post date: [March 16, 2018, 11:43am UTC](https://discourse.dry-rb.org/t/how-to-return-an-object-in-json-to-be-a-hash-and-not-a-string-hash/512/4 "2018-03-16T11:43:49Z")

</div>

Yes absolutely. Thanks much
