Skip to main content
Techie123
Silver ⭐️⭐️⭐️
Nov 28, 2022 3:21 PM UTC
Solved

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

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 

Faerballert
Gold ⭐️
Nov 28, 2022 3:47 PM UTC

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

2 replies

Faerballert
Gold ⭐️
Nov 28, 2022 3:47 PM UTC

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

Translate
Techie123
Techie123Author
Silver ⭐️⭐️⭐️
Nov 29, 2022 4:50 AM UTC

Hi @Faerballert ,

 

Its working as expected. Thank you so much. 

Translate