Search code examples
scalajson4s

Can't extract simple JSON to case class with json4s


I'm trying to use json4s in a worksheet to try it out, I want simply to extract a json to some case class:

import org.json4s.native.JsonMethods
import org.json4s.{DefaultFormats, Extraction, JValue}

case class Person(name: String, age: Int)
val json = """{"name":"joe","age":15}"""

JsonMethods.parse(json).extract[Person]

Solution

  • You forgot the implicit val jsonDefaultFormats = DefaultFormats right after your imports.