LoginSignup
3
1

More than 5 years have passed since last update.

snake caseでjsonを出力する

Posted at

気がついたらできるようになっていた

Custom Naming Strategies

      case class User(firstName: String, lastName: String)

      implicit val config = JsonConfiguration(JsonNaming.SnakeCase)
      implicit val userWrites: OWrites[User] = Json.writes[User]
      val user = User("Taro", "Yamada")

      println(Json.toJson(user).toString)

実行結果

{"first_name":"Taro","last_name":"Yamada"}

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1