skip to Main Content

I have this JSON input:

{
  "entityType": "job",
  "id": 908815,
  "properties": {
    "AvatureID": 908815,
    "TemplateName": [
      "jicofo package",
      "jitsi meet fork",
      "jitsi-videobridge2 package"
    ],
    "CaseType": [
      "Internal project",
      "Internal project",
      "Internal project"
    ],
    "ProjectType": [
      "Cloud Services",
      "Development",
      "Cloud Services"
    ],
    "Team": [
      "Cloud Operations",
      "Video",
      "Cloud Operations"
    ],
    "Category": [
      "Routine Ops",
      "Platform enhancement",
      "Routine Ops"
    ],
    "WorkflowStepID": [
      "579",
      "531",
      "579"
    ]
  }
}

And I need to get this output using a JOLT (v.0.1.1) transformation:

[
  {
    "ParentCaseID": 908815,
    "TemplateName": "jicofo package",
    "CaseType": "Internal project",
    "ProjectType": "Cloud Services",
    "Team": "Cloud Operations",
    "Category": "Routine Ops",
    "WorkflowStepID": "579"
  },
  {
    "ParentCaseID": 908815,
    "TemplateName": "jitsi meet fork",
    "CaseType": "Internal project",
    "ProjectType": "Development",
    "Team": "Video",
    "Category": "Platform enhancement",
    "WorkflowStepID": "531"
  },
  {
    "ParentCaseID": 908815,
    "TemplateName": "jitsi-videobridge2 package",
    "CaseType": "Internal project",
    "ProjectType": "Cloud Services",
    "Team": "Cloud Operations",
    "Category": "Routine Ops",
    "WorkflowStepID": "579"
  }
]

But I am having some issues when I try to add the ParentCaseID.

I am currently using this JOLT:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "TemplateName": {
          "*": {
            "@": "[&1].TemplateName"
          }
        },
        "CaseType": {
          "*": {
            "@": "[&1].CaseType"
          }
        },
        "ProjectType": {
          "*": {
            "@": "[&1].ProjectType"
          }
        },
        "Team": {
          "*": {
            "@": "[&1].Team"
          }
        },
        "Category": {
          "*": {
            "@": "[&1].Category"
          }
        },
        "WorkflowStepID": {
          "*": {
            "@": "[&1].WorkflowStepID"
          }
        }
      }
    }
  }
]

And its output is the next one:

[
  {
    "TemplateName": "jicofo package",
    "CaseType": "Internal project",
    "ProjectType": "Cloud Services",
    "Team": "Cloud Operations",
    "Category": "Routine Ops",
    "WorkflowStepID": "579"
  },
  {
    "TemplateName": "jitsi meet fork",
    "CaseType": "Internal project",
    "ProjectType": "Development",
    "Team": "Video",
    "Category": "Platform enhancement",
    "WorkflowStepID": "531"
  },
  {
    "TemplateName": "jitsi-videobridge2 package",
    "CaseType": "Internal project",
    "ProjectType": "Cloud Services",
    "Team": "Cloud Operations",
    "Category": "Routine Ops",
    "WorkflowStepID": "579"
  }
]

Is there any modification I can make to that JOLT so I can achieve the results I am looking for?

Thank you in advance!

2

Answers


  1. What is the problem when adding the ParentCaseID? I tried the following and it worked:

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "TemplateName": {
              "*": {
                "@(3,id)": "[&1].ParentCaseID",
                "@": "[&1].TemplateName"
              }
            },
            "CaseType": {
              "*": {
                "@": "[&1].CaseType"
              }
            },
            "ProjectType": {
              "*": {
                "@": "[&1].ProjectType"
              }
            },
            "Team": {
              "*": {
                "@": "[&1].Team"
              }
            },
            "Category": {
              "*": {
                "@": "[&1].Category"
              }
            },
            "WorkflowStepID": {
              "*": {
                "@": "[&1].WorkflowStepID"
              }
            }
          }
        }
      }
    ]
    

    Hope that works for you.

    Login or Signup to reply.
  2. You can combine those separate objects into single representation as in the following shift transformation, and then only pick the single values for the ones with repeated values ("ParentCaseID" array in this case) by using cardinality transformation such as

    [
      {
        "operation": "shift",
        "spec": {
          "properties": {
            "AvatureID": { "*": "" }, // this attribute vanishes
            "*": { // else case(all arrays)
              "*": { // the indexes of the respective arrays
                "@2,AvatureID": "[&].ParentCaseID",
                "@": "[&].&2"
              }
            }
          }
        }
      },
      { // remove duplicated components of the "ParentCaseID"
        // and keep only the single one.
        "operation": "cardinality",
        "spec": {
          "*": {
            "*": "ONE"
          }
        }
      }
    ]
    

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

    enter image description here

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