amatsuda / jb

A simple and fast JSON API template engine for Ruby on Rails
MIT License
1.29k stars 43 forks source link

Any way to automatically camelCase all keys? #12

Open Fire-Dragon-DoL opened 7 years ago

Fire-Dragon-DoL commented 7 years ago

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

vassilevsky commented 7 years ago

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

frederikspang commented 7 years ago

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.

ksouthworth commented 5 years ago

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

andrewclink commented 3 years ago

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.