Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to compare fields between 2 JSON objects and create a response JSON in Jolt #1260

Open
Madhavi56 opened this issue Jun 18, 2024 · 0 comments

Comments

@Madhavi56
Copy link

Request:

{
  "request1": {
    "firm": {
      "item": [
        {
          "Du": "1234",
          "Gu": "123",
          "DuNm": "QWERTy",
          "Don":{
            "donType":"Modern",
            "donValue":"0002"
          }
          
        }
      ]
    }
  },
  "request2": {
    "firm": {
      "item": [
        {
          "Du": "999999999",
          "Gu": "999999999",
          "GuNm": "Sample",
          "Mad":"Fluffy",
          "isInt":true,
          "Dusky":{
            "duskyType":"Modern",
            "duskyValue":"0002"
          }
        }
      ]
    }
  }
}

Desired Response:

{
  "original": {
    "Du": "999999999",
    "Gu": "999999999",
    "DuNm": "",
      "Don":{}
  }
}

Jolt:

Jolt I am trying so far

[
  {
    "operation": "shift",
    "spec": {
      "request1": {
        "firm": {
          "item": {
            "*": {
              "*": {
                "@5,request2.firm.item": {
                  "*": {
                    "@(&1)": "original.&2"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

Output I am getting:

{
  "original" : {
    "Du" : "999999999",
    "Gu" : "999999999"
  }
}

I want to check if the field in request1 is there or not in request2, if it is then add it in the response with the value present in request2. if the String field is not there in request2 then the its value should go as "" in output.if the Object field is not there in request2 then the its value should go as {} in output. The request1 and request2 can have multiple different fields at each time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant