I am attempting to extract the element of a List via Pattern matching.
I would NOT want to use case classes as we do not have the structure of the JSON defined upfront.
I attempted to execute the following based of your json-test example.
I am not sure if I am doing this right, but can you please point me to the right way of extracting the attributes as a tuple
val source1 = json"""{
"string": "Hello",
"int": 42,
"double": 3.14159,
"boolean": true,
"list": [{ "alpha": "test1", "beta": 1 },{ "alpha": "test2", "beta": 2 },{ "alpha": "test3", "beta": 3 }],
"foo": { "alpha": "test", "beta": 1 },
"bar": { "foo": { "alpha": "test2", "beta": 2 }, "gamma": 2.7 }
}"""
//works
source1 match {
case json""" {"list" : $l } """ => l }
//Fails
source1 match {
case json""" {"list" : [{"alpha" : $a}] } """ => a }
//Fails
source1 match {
case json""" {"list" : [{"alpha" : $a, "beta" : $b }] } """ => List[(a.as[String],b.as[Long])] }