I have a list of courses from coursera api:
{"elements":[
{"id":69,
"shortName":"contraception",
"name":"Contraception: Choices, Culture and Consequences",
"links":{}
},
...
]
}
I want to convert it to a document that look like so ( i use <--- arrrows as comments):
{"Courses":[
{
"Type" : "Course",
"Title" : "contraception" <---- short name
"Content" : {"id":69, <---- the original course
"shortName":"contraception",
"name":"Contraception: Choices, Culture and Consequences",
"links":{}
}
},
...
]}
Is it possible to perform this with json only api from play? Here is how I do it presently (with conversion to scala lists).
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" ...