Extraction using case classes

In the previous sections, we extracted specific fields from the JSON response using Scala extractors. We can do one better and extract full case classes.

When moving beyond the REPL, programming best practice dictates that we move from json4s types to Scala objects as soon as possible rather than passing json4s types around the program. Converting from json4s types to Scala types (or case classes representing domain objects) is good practice because:

  • It decouples the program from the structure of the data that we receive from the API, something we have little control over.
  • It improves type safety: a JObject is, as far as the compiler is concerned, always a JObject, whatever fields it contains. By contrast, the compiler ...

Get Scala for Data Science now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.