Accent - Plug for converting JSON API keys to different cases

Hey everyone,

I published a new package yesterday that allows a client to request the case it prefers to see the keys of a JSON response in. For example, a JavaScript client may prefer a JSON response to be in pascalCase.

The main goal of the project was to provide the client the ability to make the choice of which case they prefer rather than hard coding a snake_case to pascalCase (or whatever) conversion.

By default, a client can send an Accent header to the server with the case they prefer. Out of the box, we support pascal, camel and snake as options. Both the header used and the supported cases can be customized.

Conversion works both ways. A client can request a response be formatted with a specific case and the server can convert an incoming request to a specific case as well.

Would love to hear your thoughts!


1 Like

Huh, very use-case specific but very cool!

I’m guessing they did not want to use the GraphQL protocol or so? ^.^

A couple notes if you are curious, Elixir has snake_case / camelCase / UpperCamelCase conversion functions somewhere as I recall, can use those instead of duplicating the work as they are very well tested (since they are used in codegen). Also could add docs on the main on example usage of :supported_cases. :slight_smile:

Looks well written. :slight_smile:

Thanks for the feedback!

I’m surprised you think that the use-case is very specific. We have a lot of clients for the web services we create that prefer either pascal or camel case. I think most companies use a RESTful API as opposed to GraphQL. Glad to hear your thoughts though!

I didn’t use Elixir’s implementation because they are not Unicode compliant. They only support ASCII. They say so as much in the Macro docs.

Thanks for the documentation suggestion! I’ll definitely do that.

Thanks again! I really appreciate the time you took take a look! :smile:


These are the two non-Unicode camelize and underscore functions. Let me know if you were thinking of something else.

Thanks again!

Nah I bet that was them, I’m surprised they are not unicode compliant, that sounds like a pending PR if they would take it, though considering its built for ‘elixir identifiers’, maybe not… ^.^

1 Like