48 JSON (de)serialization with circe

 

After reading this lesson, you will be able to

  • Convert a data structure or Scala instance into JSON format
  • Parse JSON data as Scala code

You learned about asynchronous computations in the previous unit. In this lesson, you are going to learn about working with JSON in Scala. Scala doesn’t offer JSON support natively, so you’ll use circe, a popular library to work with JSON in Scala. JSON stands for “JavaScript Object Notation” and is a commonly used lightweight format to exchange straightforward data for humans to read and for machines to parse. You’ll see how to represent data in JSON format. You can refer to this process as serialization. You’ll also discover the inverse operation of defining a Scala instance by parsing a JSON structure, called deserialization. Figure 48.1 provides a visual comparison between the processes of JSON serialization and deserialization.

In the capstone, your quiz application’s HTTP API will send and receive data using the JSON format.

Figure 48.1  The process of serialization allows you to represent a Scala instance in JSON format. Its inverse is deserialization, which allows you to parse data in JSON format into a Scala instance.

48.1 Project setup

 
 
 
 

48.2 JSON serialization: From instance to JSON

 
 

48.3 JSON deserialization: From JSON to instance

 
 
 

Summary

 
 
 
 

Answers to quick checks

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest