I am trying to replicate this Python code in Scala:
import json
def test_json():
parsed = json.loads("""[{"UserName":"user1","Tags":"one, two, three"},{"UserName":"user2","Tags":"one, two, three"}]""")
tags = parsed[0]["Tags"].split(", ")
print(tags)
test_json()
And I am coming up with this gibberish which does not work:
import scala.util.parsing.json._
def testSix: Seq[String] = {
val parsed = JSON.parseFull("""[{"UserName":"user1","Tags":"one, two, three"},{"UserName":"user2","Tags":"one, two, three"}]""")
parsed.map(_ match {
case head :: tail => head
case _ => Option.empty
}).map(_ match {
case m: Map[String, String] => m("Tags").split(", ")
case _ => Option.empty
})
}
How can I get the Tags in the first entry of the json?