How to parse and extract information from json array using json4s How to parse and extract information from json array using json4s json json

How to parse and extract information from json array using json4s


Your code is correct except that your JSON is simply an array, hence a List[User]. There are two ways to fix this, with a slightly different outcome:

Solution 1: Fix your json to

{"users":   [    {"name": "Foo", "emails": ["Foo@gmail.com", "foo2@gmail.com"]},    {"name": "Bar", "emails": ["Bar@gmail.com", "bar@gmail.com"]}  ]}

Solution2: Change the type parameter of extract to

val obj = parse(json).extract[List[User]]