Search code examples
nestedspecificationsjolt

Jolt spec transformation


Trying to convert the below input to expected out.Please consider the below input and output spes..

We are forming the AppDetails by considering the "@type": "appDetails" and "arrayIndex": "0" and also we are trying to form the appActivity by consodering the "@type": "appActivity", and "@baseType": "appDetails" and to form the list, valuetype of appActivity === arrayIndexof appDetails For forming the AppActivity we should be considering the valuetype of appActivity === arrayIndexof appDetails.

please let me know if you need and further infor.. thanks Below is my Jolt input:

{
    "characteristic": [
        {
            "name": "TestRemark",
            "valueType": "string",
            "value": "251700100113",
            "@baseType": "string",
            "@schemaLocation": "string",
            "@type": "AdditionalInfo",
            "arrayIndex": "0"
        },
        {
            "name": "ID",
            "valueType": "string",
            "value": "fffcfdd2-a4e4-461b-81ca-338889a4a50b",
            "@baseType": "string",
            "@schemaLocation": "string",
            "@type": "appDetails",
            "arrayIndex": "0"
        },
        {
            "name": "FirstSignInDate",
            "valueType": "string",
            "value": "10:24:54.934",
            "@baseType": "string",
            "@schemaLocation": "string",
            "@type": "appDetails",
            "arrayIndex": "0"
        },
        {
            "name": "AppVersion",
            "valueType": "string",
            "value": "1.0",
            "@baseType": "string",
            "@schemaLocation": "string",
            "@type": "appDetails",
            "arrayIndex": "0"
        },
        {
            "name": "UserDeviceOSVersion",
            "valueType": "string",
            "value": "1.0",
            "@baseType": "string",
            "@schemaLocation": "string",
            "@type": "appDetails",
            "arrayIndex": "0"
        },
        {
            "name": "LastLoginTimestamp",
            "valueType": "string",
            "value": "2026-08-11 17:05:14.855+00",
            "@baseType": "string",
            "@schemaLocation": "string",
            "@type": "appDetails",
            "arrayIndex": "0"
        },
        {
            "name": "DeviceModel",
            "valueType": "string",
            "value": "LGE LM-G810",
            "@baseType": "string",
            "@schemaLocation": "string",
            "@type": "appDetails",
            "arrayIndex": "0"
        },
        {
            "name": "ID",
            "valueType": "string",
            "value": "fffcfdd2-a4e4-461b-81ca-338889a4a50b",
            "@baseType": "string",
            "@schemaLocation": "string",
            "@type": "appDetails",
            "arrayIndex": "1"
        },
        {
            "name": "FirstSignInDate",
            "valueType": "string",
            "value": "10:24:54.934",
            "@baseType": "string",
            "@schemaLocation": "string",
            "@type": "appDetails",
            "arrayIndex": "1"
        },
        {
            "name": "AppVersion",
            "valueType": "string",
            "value": "1.0",
            "@baseType": "string",
            "@schemaLocation": "string",
            "@type": "appDetails",
            "arrayIndex": "1"
        },
        {
            "name": "UserDeviceOSVersion",
            "valueType": "string",
            "value": "1.0",
            "@baseType": "string",
            "@schemaLocation": "string",
            "@type": "appDetails",
            "arrayIndex": "1"
        },
        {
            "name": "LastLoginTimestamp",
            "valueType": "string",
            "value": "2026-08-11 17:05:14.855+00",
            "@baseType": "string",
            "@schemaLocation": "string",
            "@type": "appDetails",
            "arrayIndex": "1"
        },
        {
            "name": "DeviceModel",
            "valueType": "string",
            "value": "LGE LM-G810",
            "@baseType": "string",
            "@schemaLocation": "string",
            "@type": "appDetails",
            "arrayIndex": "1"
        },
        {
            "name": "ActivityName",
            "valueType": "0",
            "value": "LocalLogin",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "0"
        },
        {
            "name": "ActivityType",
            "valueType": "0",
            "value": "LocalLogin",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "0"
        },
        {
            "name": "Timestamp",
            "valueType": "0",
            "value": "2022-08-11 18:10:16.779+00",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "0"
        },
        {
            "name": "Status",
            "valueType": "0",
            "value": "SUCCESSFUL",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "0"
        },
        {
            "name": "Description",
            "valueType": "0",
            "value": "MANUAL",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "0"
        },
        {
            "name": "ActivityName",
            "valueType": "1",
            "value": "LocalLogin",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "0"
        },
        {
            "name": "ActivityType",
            "valueType": "1",
            "value": "LocalLogin",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "0"
        },
        {
            "name": "Timestamp",
            "valueType": "1",
            "value": "2022-08-11 18:10:16.779+00",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "0"
        },
        {
            "name": "Status",
            "valueType": "1",
            "value": "SUCCESSFUL",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "0"
        },
        {
            "name": "Description",
            "valueType": "1",
            "value": "MANUAL",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "0"
        },
        {
            "name": "ActivityName",
            "valueType": "0",
            "value": "LocalLogin",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "1"
        },
        {
            "name": "ActivityType",
            "valueType": "0",
            "value": "LocalLogin",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "1"
        },
        {
            "name": "Timestamp",
            "valueType": "0",
            "value": "2022-08-11 18:10:16.779+00",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "1"
        },
        {
            "name": "Status",
            "valueType": "0",
            "value": "SUCCESSFUL",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "1"
        },
        {
            "name": "Description",
            "valueType": "0",
            "value": "MANUAL",
            "@baseType": "appDetails",
            "@schemaLocation": "string",
            "@type": "appActivity",
            "arrayIndex": "1"
        }
    ]
}

Expected output:

{
  "datas" : {
    "AppDetails" : [ {
      "id" : "fffcfdd2-a4e4-461b-81ca-338889a4a50b",
      "FirstSignInDate" : "10:24:54.934",
      "AppVersion" : "1.0",
      "UserDeviceOSVersion" : "1.0",
      "LastLoginTimestamp" : "2026-08-11 17:05:14.855+00",
      "DeviceModel" : "LGE LM-G810"
      "appActivity":[{
       {
                    "ActivityName": "LocalLogin",
                    "ActivityType": "LocalLogin",
                    "Timestamp": "2022-08-11 18:10:16.779+00",
                    "Status": "SUCCESSFUL",
                    "Description": "MANUAL"
                },
                {
                    "ActivityName": "LocalLogin",
                    "ActivityType": "LocalLogin",
                    "Timestamp": "2026-11-07 15:04:01.363+00",
                    "Status": "SUCCESSFUL",
                    "Description": "MANUAL"
                },
                {
                    "ActivityName": "LocalLogin",
                    "ActivityType": "LocalLogin",
                    "Timestamp": "2022-08-10 16:05:44.165+00",
                    "Status": "SUCCESSFUL",
                    "Description": "MANUAL"
                }
      
      }]
    }, {
      "id" : "fffcfdd2-a4e4-461b-81ca-338889a4a50b",
      "FirstSignInDate" : "10:24:54.934",
      "AppVersion" : "1.0",
      "UserDeviceOSVersion" : "1.0",
      "LastLoginTimestamp" : "2026-08-11 17:05:14.855+00",
      "DeviceModel" : "LGE LM-G810"
    } ]
  }
}

Solution

  • Using the below spec have got the required format. Please let me know if this can be optimized.

    [
      {
        "operation": "shift",
        "spec": {
          "responseHeader": {
            "requestId": "requestId",
            "responeId": "responeId",
            "responseStatus": "resultcode",
            "responseTimestamp": "responseTimestamp",
            "responseMessage": "resultDesc",
            "source": "source"
          },
          "characteristic": {
            "*": {
              "\\@type": {
                "appDetails": {
                  "@(2)": "datas.appDetails"
                },
                "appActivity": {
                  "@(2)": "datas.appActivities"
                }
              }
            }
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "requestId": "requestId",
          "responeId": "responeId",
          "resultcode": "resultcode",
          "responseTimestamp": "responseTimestamp",
          "resultDesc": "resultDesc",
          "source": "source",
          "datas": {
            "appDetails": {
              "*": {
                "value": {
                  "@(1,value)": "@(2,arrayIndex).@(2,name)"
                }
              }
            },
            "appActivities": {
              "*": {
                "value": {
                  "@(1,value)": "@(2,valueType).@(2,arrayIndex).@(2,name)"
                }
              }
            }
          }
        }
        }, {
        "operation": "shift",
        "spec": {
          "-1": "customerInfo[]",
          "*": "customerInfo[]",
          "requestId": "requestId",
          "responeId": "responeId",
          "resultcode": "resultcode",
          "responseTimestamp": "responseTimestamp",
          "resultDesc": "resultDesc",
          "source": "source"
        }
      },
      {
        "operation": "shift",
        "spec": {
          "customerInfo": {
            "*": {
              "ID": "datas.customerInformation.[&1].id",
              "FirstSignInDate": "datas.customerInformation.[&1].firstSignInDate",
              "AppVersion": "datas.customerInformation.[&1].appVersion",
              "UserDeviceOSVersion": "datas.customerInformation.[&1].userDeviceOSVersion",
              "LastLoginTimestamp": "datas.customerInformation.[&1].lastLoginTimestamp",
              "DeviceModel": "datas.customerInformation.[&1].deviceModel",
              "*": "datas.customerInformation[&1].appActivities"
            }
          }
        }
      }, {
        "operation": "shift",
        "spec": {
          "datas": {
            "customerInformation": {
              "*": {
                "id": "datas.customerInformation.[&1].id",
                "firstSignInDate": "datas.customerInformation.[&1].firstSignInDate",
                "appVersion": "datas.customerInformation.[&1].appVersion",
                "userDeviceOSVersion": "datas.customerInformation.[&1].userDeviceOSVersion",
                "lastLoginTimestamp": "datas.customerInformation.[&1].lastLoginTimestamp",
                "deviceModel": "datas.customerInformation.[&1].deviceModel",
                "appActivities": {
                  "*": {
                    "ActivityName": "datas.customerInformation[&3].appActivities[&1].activityName",
                    "ActivityType": "datas.customerInformation[&3].appActivities[&1].activityType",
                    "Timestamp": "datas.customerInformation[&3].appActivities[&1].timestamp",
                    "Status": "datas.customerInformation[&3].appActivities[&1].status",
                    "Description": "datas.customerInformation[&3].appActivities[&1].description"
                  }
                }
              }
            }
          }
        }
      }
    ]