- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
How to start the array of json object from Index 1 instead of 0 using Jolt NiFi
- Labels:
-
Apache NiFi
Created 11-28-2022 07:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created 11-28-2022 07:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created 11-28-2022 07:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Created 11-28-2022 08:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
