Reading snake_case attributes as camelCase in Play Json

playframework, playframework-2.0

Solution

This is a quite old question, but I didn't find any answer for it, so I went to the Play JSON Github repository and found this:

implicit val config = JsonConfiguration(SnakeCase)

implicit val userReads: Reads[PlayUser] = Json.reads[PlayUser]

So, now seems that exists an official way of doing this

https://github.com/playframework/playframework/blob/d96d42e4baa2261d0e0a9c36518f6921e247e402/documentation/manual/working/scalaGuide/main/json/code/ScalaJsonAutomatedSpec.scala#L128

Problem

I want to extract json as a case class within Play application. The attributes in case class are defined in camelCase and json data comes in snake_case. ``` case class User(userId: Long, userName: String) ``` and json would be like this {"user_name":"Vishal","user_id":67} Is there an easy way to instruct play json to automatically do the mapping and extract, like providing some annotations etc.

Original source