coursera apiからのコースのリストがあります:
{"elements":[
{"id":69,
"shortName":"contraception",
"name":"Contraception: Choices, Culture and Consequences",
"links":{}
},
...
]
}
私はそれを次のようなドキュメントに変換したい(コメントとして <--- 矢印を使用する):
{"Courses":[
{
"Type" : "Course",
"Title" : "contraception" <---- short name
"Content" : {"id":69, <---- the original course
"shortName":"contraception",
"name":"Contraception: Choices, Culture and Consequences",
"links":{}
}
},
...
]}
PlayのjsonのみのAPIでこれを実行することは可能ですか? これが現在の方法です(scalaリストへの変換を使用)。
val courses = (response.json \ "elements")
.as[List[JsValue]]
.map { course =>
// This is how we want our document to look
Json.obj(
"Type" -> "Course",
"Provider" -> "Coursera",
"Title" -> (course \ "name"),
"Content" -> course
)
}
// then put this into the final json object with "Courses" ...