I'm using Scala Play 2.7.2 and have read ScalaJsonTransformers and ScalaJson. After calling a JSON API I get back (simplified MCVE) results like this:
{
"type": "searchset",
"total": 5,
"entry": [
{
"start": "2019-06-07T09:00:00",
"end": "2019-06-07T11:00:00",
"id": "55"
},
{
"start": "2019-06-07T13:00:00",
"end": "2019-06-07T15:00:00",
"id": "56"
},
{
"start": "2019-06-07T16:00:00",
"end": "2019-06-07T17:00:00",
"id": "60"
},
{
"start": "2019-06-10T11:00:00",
"end": "2019-06-10T12:00:00",
"id": "58"
},
{
"start": "2019-06-11T14:00:00",
"end": "2019-06-11T15:00:00",
"id": "61"
}
]
}
and I'd like to filter the results and choose only the ones that satisfy a condition, for example, filter out the ones whose end date is greater than certain date val to = new DateTime("2019-06-10T00:00:00")
and doing something alla:
(json \\ "end").filter(new DateTime(_).isBefore(to.toDate.getTime))...
but this doesn't work because the result is the selection and not the entire json node and besides it leaves the outer part too.
The solution should output the result:
{
"type": "searchset",
"total": 3,
"entry": [
{
"start": "2019-06-07T09:00:00",
"end": "2019-06-07T11:00:00",
"id": "55"
},
{
"start": "2019-06-07T13:00:00",
"end": "2019-06-07T15:00:00",
"id": "56"
},
{
"start": "2019-06-07T16:00:00",
"end": "2019-06-07T17:00:00",
"id": "60"
}
}
How can this be done using Play JSON?