I'm sure there is a simple way to do this, but I haven't found a way to do it. How do I go about parsing a simple json array: [1] as a List[Integer] or List[String] with the play framework Json Library in scala?
All of the examples I have seen in the documentation assume you are working with an object and are accessing an attribute in the object. When I try to parse the json I get an error:
jsonResult.as[List[String]]
JsError(List((,List(ValidationError(error.expected.jsarray,WrappedArray())))))
jsonResultexactly?Json.parse("""[1, 2, 3, 4]""").as[List[Int]]does what you ask.. but that depends entirely on what the JSON looks like in the first place. If you don't include that, no one can determine why you are getting that error..as[List[String]]didn't work.as[List[Int]].map(_.toString)will work. Otherwise you need to define your ownReads[List[String]]for it.