- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
JoltTransformJSON - Extract attribute witouth remove it
- Labels:
-
Apache NiFi
Created ‎06-17-2019 11:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello everyone,
first at all, i am kind of newbie with nifi so feel free to change everywhting you see.
I am ussing JoltTransformJSON. My input JSON is the next one:
{
"ID": "123",
"Text1": "aaa",
"Text2": "aaa",
"Text3": "aaa"
}
And i need the next output:
{
"data": {
"ID": "123",
"Text1": "aaa",
"Text2": "aaa",
"Text3": "aaa"
},
"date": "",
"dataset": "",
"ID": "123"
}
The var date and dataset are attributes from the flow, so there is no problem here, the problem is i need to extract the value of ID, in this case 123 but this is just an example, without deleted the ID inside de field data. My Jolt Specification is the next one:
[{
"operation": "shift",
"spec": {
"*": "data.&"
}
}, {
"operation": "default",
"spec": {
"dataset": "${dataset:toLower()}",
"date": "${date}"
}
}]
and with that i have all EXCEPT the ID field, that i dont know how to do it :(.
Thankss
Created ‎06-18-2019 12:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try with below spec:
[{
"operation": "shift",
"spec": {
"*": "data.&",
"ID": ["ID", "data.ID"]
}
}, {
"operation": "default",
"spec": {
"dataset": "${dataset:toLower()}",
"date": "${date}"
}
}]
Output:
{
"ID" : "123",
"data" : {
"ID" : "123",
"Text1" : "aaa",
"Text2" : "aaa",
"Text3" : "aaa"
},
"date" : "${date}",
"dataset" : "${dataset:toLower()}"
}
Created ‎06-18-2019 12:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try with below spec:
[{
"operation": "shift",
"spec": {
"*": "data.&",
"ID": ["ID", "data.ID"]
}
}, {
"operation": "default",
"spec": {
"dataset": "${dataset:toLower()}",
"date": "${date}"
}
}]
Output:
{
"ID" : "123",
"data" : {
"ID" : "123",
"Text1" : "aaa",
"Text2" : "aaa",
"Text3" : "aaa"
},
"date" : "${date}",
"dataset" : "${dataset:toLower()}"
}
Created ‎06-18-2019 03:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The above was originally posted in the Community Help Track. On Tue Jun 18 03:07 UTC 2019, a member of the HCC moderation staff moved it to the Data Ingestion & Streaming track. The Community Help Track is intended for questions about using the HCC site itself.
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.
Created ‎06-18-2019 05:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks!! it's works
Created ‎09-30-2020 12:47 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @calonsca!
Please have a look at this spec as well!
[
{
"operation": "shift",
"spec": {
"@": "data",
"ID": "&",
"#${date}": "date",
"#${dataset:toLower()}": "dataset"
}
}
]
