skip to Main Content

I have a problem. I have an object from which I take data, merge it and then display it, but now I found out that the object can be duplicated and now I need to merge data for one object and then for the other.

Here is a JSON Input:

{
  "P6000": {
    "LocalCaseNumbers": {
      "LocalCaseNumber": [
        {
          "country": {
            "value": [
              "PL"
            ]
          },
          "caseNumber": "123",
          "Institution": {
            "institutionID": "PL:PL570050ER",
            "institutionName": "ACC_Social Insurance Institution Branch Off. in Tarnow RUM"
          }
        }
      ]
    },
    "Decisions": {
      "Decision": [
        {
          "decision": {
            "value": [
              "01"
            ]
          },
          "DetailsPensionPaymentPeriods": [
            {
              "payableFrom": "2023-09-01",
              "paymentFrequency": {
                "value": [
                  "01"
                ]
              },
              "PensionAmount": {
                "grossAmount": "1234"
              },
              "currency": {
                "value": [
                  "EUR"
                ]
              }
            },
            {
              "payableFrom": "2023-10-01",
              "paymentFrequency": {
                "value": [
                  "02"
                ]
              },
              "PensionAmount": {
                "grossAmount": "5678"
              },
              "currency": {
                "value": [
                  "HRK"
                ]
              }
            }
          ],
          "definedPension": {
            "value": [
              "01"
            ]
          },
          "awardBenefitArticle": {
            "value": [
              "01"
            ]
          },
          "actualStartDatePensionPaymentsFromInstitution": "2023-09-10",
          "typePension": {
            "value": [
              "01"
            ]
          }
        }
      ]
    },
    "InsuredPerson": {
      "AdditionalInformationPerson": {
        "Address": {
          "country": {
            "value": [
              "PL"
            ]
          },
          "town": "OPOLE",
          "postalCode": "45-401",
          "street": "KRZEMIENIECKA 16/8"
        },
        "AdditionalInformationPerson": {
          "nationality": {
            "value": [
              "PL"
            ]
          }
        }
      },
      "PersonIdentification": {
        "sex": {
          "value": [
            "02"
          ]
        },
        "PINPersonInEachInstitution": {
          "PersonalIdentificationNumber": [
            {
              "country": {
                "value": [
                  "PL"
                ]
              },
              "personalIdentificationNumber": "62081704886"
            }
          ]
        },
        "IfPINNotProvidedForEveryInstitutionPleaseProvide": {
          "PlaceBirth": {
            "country": {
              "value": [
                "PL"
              ]
            },
            "town": "RUDA ŚLĄSKA"
          }
        },
        "forename": "BOŻENA",
        "familyNameAtBirth": "MROZEK",
        "familyName": "KOTLARSKA",
        "dateBirth": "1962-08-17"
      }
    }
  }
}

Here is the JOLT spec that I have created:

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "P6000": {
        "LocalCaseNumbers": {
          "LocalCaseNumber": {
            "*": {
              "Institution": {
                "bk31x": "=concat(@(1,institutionName),'; ',@(2,caseNumber),'; ',@(5,InsuredPerson.PersonIdentification.PINPersonInEachInstitution.PersonalIdentificationNumber[0].personalIdentificationNumber),'; ',@(5,AdditionalInformationDecision.dateWhenDecisionIssuedStatedDecision))"
              }
            }
          }
        },
        "Decisions": {
          "Decision": {
            "*": {
              "DetailsPensionPaymentPeriods": {
                "*": {
                  "PensionAmount": {
                    "bk34": "=concat(@(1,grossAmount),'; ',@(2,currency.value[0]),'; ',@(2,paymentFrequency.value[0]))"
                  }
                }
              }
            }
          }
        },
        "AdditionalInformationDecision": {
          "InformationRightAReview": {
            "WhereAddressReview": {
              "*": {
                "Institution": {
                  "bk38x": "=concat(@(1,institutionName),'; ',@(2,Address.street),'; ',@(2,Address.buildingName),'; ',@(2,Address.town),'; ',@(2,Address.postalCode),'; ',@(2,Address.country.value[0]))"
                }
              }
            }
          }
        },
        "Reductions": {
          "ReductionsPension": {
            "*": {
              "size1": "=size(@(1,pensionReducedPursuantOverlappingBenefitsSameKind))",
              "size2": "=size(@(1,pensionReducedPursuantOverlappingOrBenefitsOrIncome))"
            }
          }
        }
      }
    }
    },
  {
    "operation": "shift",
    "spec": {
      "@(0,P6000.Decisions.Decision[0].decision.value[0])": {
        "01": {
          "@(2,P6000.LocalCaseNumbers.LocalCaseNumber[0].Institution.bk31x)": "p1.awardedPensionDecisions.awardedPensionDecision.bk31",
          "@(2,P6000.Decisions.Decision[0].typePension.value[0])": {
            "01": {
              "#1": "p1.awardedPensionDecisions.awardedPensionDecision.bk32"
            },
            "02": {
              "#2": "p1.awardedPensionDecisions.awardedPensionDecision.bk32"
            },
            "03": {
              "#3": "p1.awardedPensionDecisions.awardedPensionDecision.bk32"
            },
            "04": {
              "#2": "p1.awardedPensionDecisions.awardedPensionDecision.bk32"
            },
            "05": {
              "#2": "p1.awardedPensionDecisions.awardedPensionDecision.bk32"
            },
            "06": {
              "#1": "p1.awardedPensionDecisions.awardedPensionDecision.bk32"
            }
          },
          "@(2,P6000.Decisions.Decision[0].actualStartDatePensionPaymentsFromInstitution)": "p1.awardedPensionDecisions.awardedPensionDecision.paymentDetails.paymentDetail.[0].bk33",
          "@(2,P6000.Decisions.Decision[0].DetailsPensionPaymentPeriods[0].PensionAmount.bk34)": "p1.awardedPensionDecisions.awardedPensionDecision.paymentDetails.paymentDetail.[0].bk34",
          "@(2,P6000.Decisions.Decision[0].awardBenefitArticle.value[0])": {
            "01": {
              "#4": "p1.awardedPensionDecisions.awardedPensionDecision.bk35"
            },
            "02": {
              "#5": "p1.awardedPensionDecisions.awardedPensionDecision.bk35"
            },
            "03": {
              "#6": "p1.awardedPensionDecisions.awardedPensionDecision.bk35"
            },
            "04": {
              "#6": "p1.awardedPensionDecisions.awardedPensionDecision.bk35"
            }
          },
          "@(2,P6000.Reductions.ReductionsPension[0].size1)": {
            "0": {
              "@(5,P6000.Reductions.ReductionsPension[0].size2)": {
                "0": {
                  "": "p1.awardedPensionDecisions.awardedPensionDecision.bk36"
                },
                "*": {
                  "#7": "p1.awardedPensionDecisions.awardedPensionDecision.bk36"
                }
              }
            },
            "*": {
              "#7": "p1.awardedPensionDecisions.awardedPensionDecision.bk36"
            }
          },
          "@(2,P6000.LocalCaseNumbers.LocalCaseNumber[0].country.value[0])": {
            "PL": {
              "#w każdym czasie": "p1.awardedPensionDecisions.awardedPensionDecision.bk37"
            },
            "*": {
              "": "p1.awardedPensionDecisions.awardedPensionDecision.bk37"
            }
          },
          "@(2,P6000.AdditionalInformationDecision.InformationRightAReview.WhereAddressReview[0].Institution.bk38x)": "p1.awardedPensionDecisions.awardedPensionDecision.bk38",
          "# ": "p1.awardedPensionDecisions.awardedPensionDecision. "
        },
        "02": {
          "@(2,P6000.LocalCaseNumbers.LocalCaseNumber[0].Institution.bk31x)": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk41",
          "@(2,P6000.Decisions.Decision[0].typePension.value[0])": {
            "01": {
              "#1": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk42"
            },
            "02": {
              "#2": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk42"
            },
            "03": {
              "#3": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk42"
            },
            "04": {
              "#2": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk42"
            },
            "05": {
              "#2": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk42"
            },
            "06": {
              "#1": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk42"
            }
          },
          "@(2,P6000.Decisions.Decision[0].RejectionReasons[0].rejectionReasons.value[0])": {
            "01": {
              "#4": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk43"
            },
            "02": {
              "#5": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk43"
            },
            "03": {
              "#6": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk43"
            },
            "04": {
              "#7": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk43"
            },
            "05": {
              "#8": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk43"
            },
            "06": {
              "#9": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk43"
            },
            "07": {
              "#10": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk43"
            },
            "08": {
              "#10": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk43"
            },
            "99": {
              "#10": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk43"
            }
          },
          "@(2,P6000.LocalCaseNumbers.LocalCaseNumber[0].country.value[0])": {
            "PL": {
              "#w każdym czasie": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk44"
            },
            "*": {
              "": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk44"
            }
          },
          "@(2,P6000.AdditionalInformationDecision.InformationRightAReview.WhereAddressReview[0].Institution.bk38x)": "p1.rejectedPensionDecisions.rejectedPensionDecision.bk45",
          "# ": "p1.rejectedPensionDecisions.rejectedPensionDecision. "
        }
      }
    }
    }
]


I have this result:

{
  "p1" : {
    "awardedPensionDecisions" : {
      "awardedPensionDecision" : {
        "bk31" : "ACC_Social Insurance Institution Branch Off. in Tarnow RUM; 123; 62081704886; ",
        "bk32" : "1",
        "paymentDetails" : {
          "paymentDetail" : [ {
            "bk33" : "2023-09-10",
            "bk34" : "1234; EUR; 01"
          } ]
        },
        "bk35" : "4",
        "bk37" : "w ka?dym czasie",
        " " : " "
      }
    }
  }
}


But I expect this result:

{
  "p1" : {
    "awardedPensionDecisions" : {
      "awardedPensionDecision" : {
        "bk31" : "ACC_Social Insurance Institution Branch Off. in Tarnow RUM; 123; 62081704886; ",
        "bk32" : "1",
        "paymentDetails" : {
          "paymentDetail" : [ {
            "bk33" : "2023-09-10",
            "bk34" : "1234; EUR; 01"
          }, {
            "bk33" : "2023-09-10",
            "bk34" : "5678; HRK; 02"
          }  ]
        },
        "bk35" : "4",
        "bk37" : "w ka?dym czasie",
        " " : " "
      }
    }
  }
}


3

Answers


  1. To achieve the expected result where you merge data for multiple objects, you need to iterate through the Decision array and create multiple output objects. You can do this using Jolt’s shift operation combined with looping constructs. Below is the modified JOLT spec that should give you the desired result:

    [
      {
        "operation": "shift",
        "spec": {
          "X.Decisions.Decision[0].DetailsPensionPaymentPeriods": {
            "*": {
              "PensionAmount": {
                "grossAmount": "p1.awardedPensionDecisions.awardedPensionDecision.paymentDetails.paymentDetail[&1].bk34",
                "currency": {
                  "value": {
                    "0": "p1.awardedPensionDecisions.awardedPensionDecision.paymentDetails.paymentDetail[&1].bk34Currency"
                  }
                },
                "paymentFrequency": {
                  "value": {
                    "0": "p1.awardedPensionDecisions.awardedPensionDecision.paymentDetails.paymentDetail[&1].bk34Frequency"
                  }
                }
              }
            }
          },
          "X.Decisions.Decision[0].actualStartDatePensionPaymentsFromInstitution": "p1.awardedPensionDecisions.awardedPensionDecision.paymentDetails.paymentDetail[0].bk33"
        }
      },
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "p1.awardedPensionDecisions.awardedPensionDecision.paymentDetails.paymentDetail[0].bk34": "=concat(@(1,p1.awardedPensionDecisions.awardedPensionDecision.paymentDetails.paymentDetail[0].bk34), ', ', @(2,p1.awardedPensionDecisions.awardedPensionDecision.paymentDetails.paymentDetail[1].bk34))"
        }
      }
    ]
    
    Login or Signup to reply.
  2. You can use the following transformation as an option

    [
      { // construct the innermost array "PaymentDetail"
        "operation": "shift",
        "spec": {
          "*": {
            "@Decisions.Decision": {
              "*": {
                "DetailsPensionPaymentPeriods": {
                  "*": {
                    "@2,actualStartDatePensionPaymentsFromInstitution": "PaymentDetail[&].bk33",
                    "@PensionAmount.grossAmount": "PaymentDetail[&].bk34",
                    "@currency.value|@paymentFrequency.value": {
                      "*": "PaymentDetail[&1].bk34"
                    }
                  }
                }
              }
            }
          }
        }
      },
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": {
            "*": {
              "*4": "=join('; ',@(1,&))" // semi-colon separartedly concatenate components of bk34
            }
          }
        }
      },
      { // add upper nodes to the "PaymentDetail" array
        "operation": "shift",
        "spec": {
          "@": "Y.awardedPensionDecisions.awardedPensionDecision.paymentDetails"
        }
      }
    ]
    

    the demo on the site http://jolt-demo.appspot.com/ is :

    enter image description here

    Login or Signup to reply.
  3. The following spec will work for you. I assume you need to display the value only if decision.value[0]= "01". Let me know if that is not the case.

    [
      {
        "operation": "modify-default-beta",
        "spec": {
          "X": {
            "Decisions": {
              "Decision": {
                "*": {
                  "DetailsPensionPaymentPeriods": {
                    "*": {
                      "PensionAmount": {
                        "bk34": "=concat(@(1,grossAmount),'; ',@(2,currency.value[0]),'; ',@(2,paymentFrequency.value[0]))"
                      }
                    }
                  }
                }
              }
            }
          }
        }
        },
      {
        "operation": "shift",
        "spec": {
          "@X.Decisions.Decision[0]": {
            "DetailsPensionPaymentPeriods": {
              "*": {
                "PensionAmount": {
                  "@(3,decision.value[0])": {
                    "01": {
                      "@(5,actualStartDatePensionPaymentsFromInstitution)": "p1.awardedPensionDecisions.awardedPensionDecision.paymentDetails.paymentDetail[&4].bk33",
                      "@(2,bk34)": "p1.awardedPensionDecisions.awardedPensionDecision.paymentDetails.paymentDetail[&4].bk34"
                    }
                  }
                }
              }
            }
          }
        }
      }
    ]
    
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search