0

I have a Json string in the format:

{
  "id": {
    "1": {
       "name": "Andrew",
       "age":  12,
       "alive": "yes"
         },
    "2": {
       "name": "Susan",
       "age":  14,
       "alive": "yes"
         }
       }
}

What is the best way to convert this into a case class in Scala?

The case class would be in the following format:

case class JsonParent(key:String, jsonNested : List[JsonChild] ) case class JsonChild(key:String, jsonNested1 : List[JsonChildValues]) case class JsonChildValues(name:String, age:Int, alive:Boolean)

Is this possible, if so what would be the best way to do it?

  • I haven't been able to find one that can do what I require with simplicity – Sagar Patel Jul 17 '16 at 14:20
  • I feel that "simplicity" is subjective. To answer this question, all YOU need to do is look at all the available JSON parsing library and choose your prefered one: https://github.com/lauris/awesome-scala#json – JRomero Jul 17 '16 at 16:37

1 Answers1

0

Try circe:

https://github.com/travisbrown/circe

For example, you can do the following with circe: decode[YourCaseClass](your_json_string)

AFR
  • 46
  • 2