- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Apache NiFi need to add square brackets around a specific JSON object
- Labels:
-
Apache NiFi
Created on 08-29-2024 09:06 AM - edited 08-29-2024 09:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm new to NiFi, and I've been struggling with wrapping square brackets around a specific JSON object. Below is my JSON input, my desired JSON output and my attempted JoltTransformJSON shift operation spec. I'm really close, but I'm getting a duplicate of the "financialSystemFields" object.
Please advise, and many thanks in advance.
JSON Input:
[{
"type" : "APPROPRIATION",
"subType" : "ADMINISTRATIVE",
"duration" : "1",
"retiredDate" : null,
"expiredDate" : "2023-09-30 00:00:00.0",
"closedDate" : "2028-09-30 00:00:00.0",
"association" : null,
"financialSystemFields" : {
"FundId" : "01234NFWJ",
"fundedProgram" : null,
"projectDescription" : "NO FUN WITH JOLT"
}
}]
Current JSON Output:
[{
"type": "APPROPRIATION",
"subType": "ADMINISTRATIVE",
"duration": "1",
"retiredDate": null,
"expiredDate": "2023-09-30 00:00:00.0",
"closedDate": "2028-09-30 00:00:00.0",
"association": null,
"financialSystemFields": [{
"FundId": "01234NFWJ",
"fundedProgram": null,
"projectDescription": "NO FUN WITH JOLT"
}, {
"FundId": "01234NFWJ",
"fundedProgram": null,
"projectDescription": "NO FUN WITH JOLT"
}]
}]
Desired JSON Output:
[{
"type": "APPROPRIATION",
"subType": "ADMINISTRATIVE",
"duration": "1",
"retiredDate": null,
"expiredDate": "2023-09-30 00:00:00.0",
"closedDate": "2028-09-30 00:00:00.0",
"association": null,
"financialSystemFields": [{
"FundId": "01234NFWJ",
"fundedProgram": null,
"projectDescription": "NO FUN WITH JOLT"
}]
}]
Jolt Operation:
[{
"operation": "shift",
"spec": {
"*": {
"@": "[&1]",
"@(0,financialSystemFields)": "[&].financialSystemFields"
}
}
}]
Created 08-29-2024 12:25 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've figured out what needs to be done. The following fixed the issue.
[{
"operation": "cardinality",
"spec": {
"financialSystemFields": "MANY"
}
}]
Created 08-29-2024 10:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@JoltInfan Welcome to the Cloudera Community!
To help you get the best possible solution, I have tagged our NiFi experts @MattWho @vaishaakb who may be able to assist you further.
Please keep us updated on your post, and we hope you find a satisfactory solution to your query.
Regards,
Diana Torres,Senior Community Moderator
Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community:
Created 08-29-2024 12:25 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've figured out what needs to be done. The following fixed the issue.
[{
"operation": "cardinality",
"spec": {
"financialSystemFields": "MANY"
}
}]
