This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 15.2, “How to create a JSON String from Scala classes that have collections.”
Problem
You want to generate a JSON representation of a Scala object that contains one or more collections, such as a Person
class that has a list of friends or addresses.