6 quick tips to Parse JSON with Circe

Edward Huang
6 min readNov 30, 2019

(Originally published at https://edward-huang.com)

Marshall and Unmarhsall JSON is the bread and butter of ETL. There has been much library that gives ways to help the data wrangling process much seamless. One of these JSON libraries that gain much popularity lately is Circe. It is a library that creates a shapeless dependency that has an automatic deserialization function that serializes JSON string to a domain model. However, these JSON libraries also come with a catch. For example, you keep encountering decode failure if you don’t know what you need to use the prepare method to handle class with default on the non-optional field. Decoding nested arrays and objects is hard if you don't know some vital work around the libraries. You encounter a lot of questions, such as what is the difference between auto and semi-auto, and when do you need to use one vs. the other?

These questions can sometimes be daunting. I spent days and weeks, scratching my head, pulling my hair, understand and learn all the best practices in using this JSON library — I concluded 6 simple tips that I learn that can save you tons of time in using Circe in your future Scala projects.

Setup

Before we started, let’s setup up the environment. If you haven’t set up SBT, you can look at the documentation here. Paste the dependency on…

--

--

Edward Huang
Edward Huang

Written by Edward Huang

Follow my Newsletter @ https://pathtosenior.substack.com/ | Twitter: @Huan72349Edward | Medium Publication Index @ https://forms.gle/YfyssUruGUKyATXy9

No responses yet