1
votes

I have a JSON which have studentId's who play cricket and I want a student list for each object of the group array. But the output is getting merged into the same student list. I tried iterating each and every studentId and getting the below output. And I wish to get the output like in the below expected/desired format. Any help?

Input:

{
  "studentEligibility": {
    "sportsEligibility": {
      "cricketEligibility": [
        {
          "group": [
            {
              "multiPlayGame": [
                {
                  "studentId": "2aefcb01-fe81-4760-b531-9767c2e6d322_209537"
                },
                {
                  "studentId": "2aefcb01-fe81-4760-b531-9767c2e6d322_217649"
                }
              ]
            }
          ]
        },
        {
          "group": [
            {
              "multiPlayGame": [
                {
                  "studentId": "2aefcb01-fe81-4760-b531-9767c2e6d322_217609"
                }
              ]
            },
            {
              "multiPlayGame": [
                {
                  "studentId": "2aefcb01-fe81-4760-b531-9767c2e6d322_216386"
                }
              ]
            }
          ]
        },
        {
          "group": [
            {
              "multiPlayGame": [
                {
                  "studentId": "2aefcb01-fe81-4760-b531-9767c2e6d322_217008"
                },
                {
                  "studentId": "2aefcb01-fe81-4760-b531-9767c2e6d322_217628"
                }
              ]
            }
          ]
        }
      ]
    }
  }
}

Jolt Spec:

[
  {
    "operation": "shift",
    "spec": {
      "studentEligibility": {
        "sportsEligibility": {
          "cricketEligibility": {
            "*": {
              "group": {
                "*": {
                  "multiPlayGame": {
                    "*": {
                      "studentId": "team[&5].players[]"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

Current Ouptut:

{
  "team": [
    {
      "players": [
        "2aefcb01-fe81-4760-b531-9767c2e6d322_209537",
        "2aefcb01-fe81-4760-b531-9767c2e6d322_217649"
      ]
    },
    {
      "players": [
        "2aefcb01-fe81-4760-b531-9767c2e6d322_217609",
        "2aefcb01-fe81-4760-b531-9767c2e6d322_216386"
      ]
    },
    {
      "players": [
        "2aefcb01-fe81-4760-b531-9767c2e6d322_217008",
        "2aefcb01-fe81-4760-b531-9767c2e6d322_217628"
      ]
    }
  ]
}

Expected / Desired output:

{
  "team": [
    {
      "players": [
        "2aefcb01-fe81-4760-b531-9767c2e6d322_209537",
        "2aefcb01-fe81-4760-b531-9767c2e6d322_217649"
      ]
    },
    {
      "players": [
        "2aefcb01-fe81-4760-b531-9767c2e6d322_217609"
      ]
    },
    {
      "players": [
        "2aefcb01-fe81-4760-b531-9767c2e6d322_216386"
      ]
    },
    {
      "players": [
        "2aefcb01-fe81-4760-b531-9767c2e6d322_217008",
        "2aefcb01-fe81-4760-b531-9767c2e6d322_217628"
      ]
    }
  ]
}
1
Please share your attempt so that other S/O users may add suggestions or assist you. - ggordon
hi @ggordon, if you look again there is already Jolt Spec done by me was there. An edit to it will help my issue. hope u have some knowledge on jolt transformation else it's difficult for us to communicate - Arun Sai
Apologies, I have shared a jolt spec that will achieve this transformation - ggordon
It happens, No problem, Thanks a lot for the help, am a bit weaker in looping concepts using jolt code and will learn from it. - Arun Sai

1 Answers

2
votes

Jolt Spec Solution

[
  {
    "operation": "shift",
    "spec": {
      "studentEligibility": {
        "sportsEligibility": {
          "cricketEligibility": {
            "*": {
              "group": {
                "*": "teams[].players[]"
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "teams": {
        "*": {
          "players": {
            "*": {
              "multiPlayGame": "team.players[]"
            }
          }
        }
      }
    }
  },

  {
    "operation": "shift",
    "spec": {
      "team": {
        "players": {
          "*": {
            "*": {
              "studentId": "team[&2].players[]"
            }
          }
        }
      }
    }
  }
]