0

I have the following JSON

{
    "transactionId" : "123456789",
    "amount" : 215,
    "refunds" : {
       "detail" : [
           {
               "id" : 12345,
               "amount" : 7
           },
           {
               "id" : 67890,
               "amount" : 15
           }
       ],
       "total_amount" : 22
   }
}

I need to extract the information from the refunds node, where the id = 12345 using only jsonlogic.

Exploring the operations supported by jsonlogic, I found that it has an operation for arrays called filter (link), but I have only found examples for arrays of basic data types (int, string, etc) but not for arrays of objects.

Does anyone have any idea how it could be?

mleko
  • 11,650
  • 6
  • 50
  • 71
Alejandro Herrera
  • 411
  • 1
  • 5
  • 22

1 Answers1

0

Doing different tests I found out that it is possible to filter this information using the filter operation.

the filter is as follows:

{"filter":[{"var":"refunds.detail"},{"==":[{"var":".id"},"12345"]}]}

the crucial part is to add before the field to filter the character "."

Alejandro Herrera
  • 411
  • 1
  • 5
  • 22