# \[dry-struct\] Create camel case output of the object

**URL:** <https://discourse.dry-rb.org/t/dry-struct-create-camel-case-output-of-the-object/1570>\
**Category:** Support\
**Created:** [December 12, 2022, 8:24pm UTC](https://discourse.dry-rb.org/t/dry-struct-create-camel-case-output-of-the-object/1570 "2022-12-12T20:24:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wichru](https://avatars.discourse-cdn.com/v4/letter/w/a4c791/32.png) [@wichru](https://discourse.dry-rb.org/u/wichru)\
**Post date:** [December 12, 2022, 8:24pm UTC](https://discourse.dry-rb.org/t/dry-struct-create-camel-case-output-of-the-object/1570/1 "2022-12-12T20:24:59Z")

</div>

Hi there 👋

I’ve to build a massive JSON file based on few different API calls. I want to use Dry::Struct To easily manipulate that data like:

```auto
obj = Test::DataStruct.new
obj.send_envelope_description = 1

```

but expected output should be camelcase:  
`#<Test::DataStruct SendEnvelopeDescription=1>`

Additionally, passed data should into Test::DataStruct obj should accept camelcase keys like:

```auto
data = { SendEnvelopeDescription: 1 }
test = TestDataStruct.new(data)
 => #<Test::DataStruct SendEnvelopeDescription=1>

```

I tried to use `transform_keys { |key| key.to_s.camelize }` but when I’m getting an error:

```auto
3.1.2 :045 > obj = Test::DataStruct.new(send_envelope_description: 1)

`block in resolve_missing_keys': [Test::DataStruct.new] :send_envelope_description is missing in Hash input (Dry::Struct::Error)

`block in resolve_missing_keys': :send_envelope_description is missing in Hash input (Dry::Types::MissingKeyError)

```

Is it possible to do so?

---

<div class="post-metadata">

**Author:** ![flash-gordon](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/flash-gordon/32/494_2.png) [@flash-gordon](https://discourse.dry-rb.org/u/flash-gordon)\
**Post date:** [December 14, 2022, 9:13am UTC](https://discourse.dry-rb.org/t/dry-struct-create-camel-case-output-of-the-object/1570/2 "2022-12-14T09:13:05Z")

</div>

I don’t think dry-struct is supposed to deal with the matter. Just write a function that recursively transforms keys of a hash input, it’s 10 lines of code basically. This is what I use

```ruby
      def camelize(value)
        case value
        when ::Array
          value.map { camelize(_1) }
        when ::Hash
          value.to_h do |key, v|
            [Dry::Inflector.camelize_lower(key.to_s).to_sym, camelize(v)]
          end
        else
          value
        end
      end

```

Then

```ruby
camelize(struct.to_h)

```
