JSON Naming Convention (snake_case, camelCase or PascalCase) [closed]

In this document Google JSON Style Guide (recommendations for building JSON APIs at Google),

It recommends that:

  1. Property names must be camelCased, ASCII strings.

  2. The first character must be a letter, an underscore (_), or a dollar sign ($).

Example:

{
  "thisPropertyIsAnIdentifier": "identifier value"
}

My team consistently follows this convention when building REST APIs. There are some reasons:

  • First, the JSON convention should be independent of the programming languages because we want our APIs to be consistent doesn’t matter whether there are some APIs implemented using a camelCase language (e.g. Java), some others using snake_case language (e.g. Python).
  • Also, most of our clients are webapp so camelCase is preferred
  • If the client prefers snake_case, it still can easily convert data between snake_case and camelCase (with the help of libraries)

But I agree that if all the applications use the same type of language (e.g. snake_case), the JSON convention should also follow.

Leave a Comment