0

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())))))
5
  • 1
    Well... what is jsonResult exactly? Commented Dec 8, 2014 at 19:57
  • A WSResponse that was mapped to a json Commented Dec 8, 2014 at 20:04
  • For example 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. Commented Dec 8, 2014 at 20:05
  • Hmmm... That worked (minus the quotations cause I don't need them) but for some reason .as[List[String]] didn't work Commented Dec 8, 2014 at 20:09
  • 1
    That's because an array of Ints won't be read as Strings. .as[List[Int]].map(_.toString) will work. Otherwise you need to define your own Reads[List[String]] for it. Commented Dec 8, 2014 at 20:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.