camelCase or snake_case for json parameters

Any advice on camelCase vs. snake_case for json parameters, to and from a Rails server.

I’m guessing on standardizing on snake_case, because Rails will send back database objects with with attributes in snake case.

However, it’s really hard to remember on the javascript side when an object attribute is in snake case!

Maybe a reasonable default is to give the other side what the other side expects:

  1. Rails gives JavaScript camelCase.
  2. JavaScript gives Rails snake_case.

The Google JSON guide states:

Property names must conform to the following guidelines:

  • Property names should be meaningful names with defined semantics.
  • Property names must be camel-cased, ascii strings.
  • The first character must be a letter, an underscore (_) or a dollar sign ($).
  • Subsequent characters can be a letter, a digit, an underscore, or a dollar sign.
  • Reserved JavaScript keywords should be avoided (A list of reserved JavaScript keywords can be found below).
  • These guidelines mirror the guidelines for naming JavaScript identifiers. This allows JavaScript clients to access properties using dot notation. (for example, result.thisIsAnInstanceVariable). Here’s an example of an object with one property:

“thisPropertyIsAnIdentifier”: “identifier value”

I’ve struggled a bit with this - it’s especially bad when you’re building a polyglot application. It feels weird, but then in my JS I find myself doing a lot of var someAttribute = body.some_attribute to keep the “different” stuff confined to the edges of my code.