jb icon indicating copy to clipboard operation
jb copied to clipboard

Any way to automatically camelCase all keys?

Open Fire-Dragon-DoL opened this issue 8 years ago • 4 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

Fire-Dragon-DoL avatar Mar 23 '17 18:03 Fire-Dragon-DoL

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

vassilevsky avatar Jun 11 '17 10:06 vassilevsky

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.

frederikspang avatar Jul 30 '17 22:07 frederikspang

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

ksouthworth avatar Sep 16 '19 15:09 ksouthworth

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.

andrewclink avatar Jan 12 '21 05:01 andrewclink