Support Questions

Find answers, ask questions, and share your expertise

How to start the array of json object from Index 1 instead of 0 using Jolt NiFi

avatar
Contributor

Hi Team,

 

I have an requirement:

 

Input:

{
"headers": {
"comments": "3"
},
"data": [
{
"Id": "100000",
"Date": "2022-09-22"
},
{
"Id": "100001",
"Date": "2022-09-02"
}
]
}

 

Jolt Spec:

[{
"operation": "shift",
"spec": {
"data": {
"*": {
"Id": "[&1].Id",
"Date": "[&1].Date",
"$": "[&1].array_Ind"
}
}
}
}, {
"operation": "modify-default-beta",
"spec": {
"*": {
"Record": "=concat('Record ',@(1,array_Ind))"
}
}
}]

 

I am getting below output:

[ {
"array_Ind" : "0",
"Id" : "100000",
"Date" : "2022-09-22",
"Record" : "Record 0"
}, {
"array_Ind" : "1",
"Id" : "100001",
"Date" : "2022-09-02",
"Record" : "Record 1"
} ]

 

Expected output:

 

[ {
"array_Ind" : "1",
"Id" : "100000",
"Date" : "2022-09-22",
"Record" : "Record 1"
}, {
"array_Ind" : "2",
"Id" : "100001",
"Date" : "2022-09-02",
"Record" : "Record 2"
} ]  

 

Can you please help 

1 ACCEPTED SOLUTION

avatar
Expert Contributor

Hello @Techie123  

 

I added a operation to your Jolt Specification, try it with:

 

[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "*": {
          "Id": "[&1].Id",
          "Date": "[&1].Date",
          "$": "[&1].array_Ind"
        }
      }
    }
}, {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "array_Ind": "=intSum(1,@(1,array_Ind))"
      }
    }
  }, {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "Record": "=concat('Record ',@(1,array_Ind))"
      }
    }
  }
]

Greetings

View solution in original post

2 REPLIES 2

avatar
Expert Contributor

Hello @Techie123  

 

I added a operation to your Jolt Specification, try it with:

 

[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "*": {
          "Id": "[&1].Id",
          "Date": "[&1].Date",
          "$": "[&1].array_Ind"
        }
      }
    }
}, {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "array_Ind": "=intSum(1,@(1,array_Ind))"
      }
    }
  }, {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "Record": "=concat('Record ',@(1,array_Ind))"
      }
    }
  }
]

Greetings

avatar
Contributor

Hi @Faerballert ,

 

Its working as expected. Thank you so much.