amatsuda / jb

A simple and fast JSON API template engine for Ruby on Rails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any way to automatically camelCase all keys?

Fire-Dragon-DoL opened this issue · comments

Hello! In ruby we use snake_case everywhere and I suffer when I have to camelCase in any place.
Is there any option to camelKeys automatically all keys right before spitting out the JSON?

I would use it so that my JSON api stays consistent with javascript notation

We are solving this problem in our projects with https://github.com/RSCSCybersecurity/sparrow and it works pretty well.

Or in case you wanna avoid using an extra middleware (Which isn't a bad solution, but some might prefer not to), you could in your builder-files use .camelize(:lower) for the keys, if you're settings the attributes dynamically.

I agree with @Fire-Dragon-DoL it would be great to have support for automatically camelCasing keys for output.

Something like the olive_branch gem https://github.com/vigetlabs/olive_branch

I was using a MultiJson.use(MyCustomKeyTransformer) to do this, and it worked pretty well. Unfortunately a JB commit in October seems to have broken multi_json support. Multi_json does provide a nice two-way API, though, if the situation is solvable.