Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

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.