The json I have looks like this:
{
"cards": [
{
"card_id":"1234567890",
"card_status":"active",
"card_expiration":{
"formatted":"01/20"
},
"debit":{
"masked_debit_card_number":"1111 **** **** 1111",
}
},
{
"card_id":"1234567891",
"card_status":"active",
"card_expiration":null,
"debit":{
"masked_debit_card_number":"2222 **** **** 2222",
}
}
]
}
I'm trying to retrieve all card_expiration
fields values using this function:
def getExpirations(json: Json) =
root
.cards
.each
.filter(root.card_status.string.exist(_ == "active"))
.card_expiration
.selectDynamic("formatted")
.string
.getAll(json)
The thing is, the above expression only returns 1 result - for the first card, but I really need to get something like List(Some("01/20"), None)
! What can I do in this situation?
The issue is that by the time you've done the
formatted
step you're no longer matching thenull
expiration. You could do something like this:Or:
And then:
Without more context, it's not clear in my view that this is a good use case for circe-optics. You're probably better off decoding into case classes, or maybe using cursors. If you can provide more information it'd be easier to tell.