Jolt for getting proper URLs list

22 views Asked by At

Can someone help me transform my input data here? Below is the Jolt I have written but does not provide the output I want, it transforms the input into an array. But I would like to transform my input into a list.

This is the input:

[
  {
    "domain-specific-features": {
      "features": [
        {
          "id": 3581,
          "name": "search-hello"
        },
        {
          "id": 3582,
          "name": "search-rmn"
        },
        {
          "id": 3864,
          "name": "search-email"
        },
        {
          "id": 3865,
          "name": "search-sr"
        },
        {
          "id": 3866,
          "name": "search-order"
        },
        {
          "id": 3867,
          "name": "search-disconnected-customer"
        },
        {
          "id": 3868,
          "name": "search-customer-id"
        },
        {
          "id": 3869,
          "name": "search-customer-number"
        }
      ]
    }
  },
  {
    "input": {
      "mobile-number": "1234567890",
      "pattern": "search"
    }
  }
]

This is the jolt I have tried and am getting URLs in an array:

[
    {
        "operation": "shift",
        "spec": {
            "*": {
                "domain-specific-features": {
                    "resultStatus": "resultStatus",
                    "features": {
                        "*": "mobility\\-callerId\\-featureList[].feature"
                    }
                },
                "input": "input"
            }
        }
    },
    {
        "operation": "shift",
        "spec": {
            "resultStatus": "resultStatus",
            "mobility\\-callerId\\-featureList": {
                "*": {
                    "@(2,input)": {
                        "mobile-number": "mobility\\-callerId\\-featureList[&2].mobileNumber",
                        "pattern": "mobility\\-callerId\\-featureList[&2].pattern"
                    },
                    "*": "mobility\\-callerId\\-featureList[&1].&"
                }
            }
        }
    },
    {
        "operation": "modify-overwrite-beta",
        "spec": {
            "mobility\\-call*rId\\-featureList": {
                "*": {
                    "fea*ure": {
                        "mobility\\-callerId\\-featureList\\-url": "=concat('/epsp-pattern/',@(2,pattern),'/',@(1,name),'?', 'mobile-number=', @(2,mobileNumber), '&appPatternFeatureId=', @(1,id))"
                    }
                }
            }
        }
    },
    {
        "operation": "shift",
        "spec": {
            "resultStatus": {
                "#NO_RECORD": "resultStatus.status",
                "#No records found": "resultStatus.message",
                "#7000": "resultStatus.code"
            },
            "mobility\\-callerId\\-featureList": {
                "*": {
                    "feature": {
                        "mobility\\-callerId\\-featureList\\-url": "mobility\\-callerId\\-featureList[&2].&"
                    }
                }
            }
        }
    }
]

This is my expected output:

{
  "mobility-callerId-featureList" : ["/epsp-pattern/search/search-hello?mobile-number=1234567890&appPatternFeatureId=3581", "/epsp-pattern/search/search-rmn?mobile-number=1234567890&appPatternFeatureId=3582", "/epsp-pattern/search/search-email?mobile-number=1234567890&appPatternFeatureId=3864", "/epsp-pattern/search/search-sr?mobile-number=1234567890&appPatternFeatureId=3865", "/epsp-pattern/search/search-order?mobile-number=1234567890&appPatternFeatureId=3866", "/epsp-pattern/search/search-disconnected-customer?mobile-number=1234567890&appPatternFeatureId=3867", "/epsp-pattern/search/search-customer-id?mobile-number=1234567890&appPatternFeatureId=3868", "/epsp-pattern/search/search-customer-number?mobile-number=1234567890&appPatternFeatureId=3869"]
}
1

There are 1 answers

0
Trần Quang Sơn On

You may shift your output one more time to get the desired output:

[
  {
    "operation": "shift",
    "spec": {
      "*": { //matches the top-level key (mobility-callerId-featureList)
        "*": { //matches each object within the array
          "*": "&" //matches each key-value pair within the nested objects.
    //'&' to keep the value and place it directly under the top-level key
        }
      }
    }
  }
]

So your whole Jolt becomes this:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "domain-specific-features": {
          "resultStatus": "resultStatus",
          "features": {
            "*": "mobility\\-callerId\\-featureList[].feature"
          }
        },
        "input": "input"
      }
    }
    },
  {
    "operation": "shift",
    "spec": {
      "resultStatus": "resultStatus",
      "mobility\\-callerId\\-featureList": {
        "*": {
          "@(2,input)": {
            "mobile-number": "mobility\\-callerId\\-featureList[&2].mobileNumber",
            "pattern": "mobility\\-callerId\\-featureList[&2].pattern"
          },
          "*": "mobility\\-callerId\\-featureList[&1].&"
        }
      }
    }
    },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "mobility\\-call*rId\\-featureList": {
        "*": {
          "fea*ure": {
            "mobility\\-callerId\\-featureList\\-url": "=concat('/epsp-pattern/',@(2,pattern),'/',@(1,name),'?', 'mobile-number=', @(2,mobileNumber), '&appPatternFeatureId=', @(1,id))"
          }
        }
      }
    }
    },
  {
    "operation": "shift",
    "spec": {
      "resultStatus": {
        "#NO_RECORD": "resultStatus.status",
        "#No records found": "resultStatus.message",
        "#7000": "resultStatus.code"
      },
      "mobility\\-callerId\\-featureList": {
        "*": {
          "feature": {
            "mobility\\-callerId\\-featureList\\-url": "mobility\\-callerId\\-featureList[&2].&"
          }
        }
      }
    }
    },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": "&"
        }
      }
    }
  }
]

enter image description here