Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

JoltTransformJSON - Extract attribute witouth remove it

Solved Go to solution

JoltTransformJSON - Extract attribute witouth remove it

New Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions

Re: JoltTransformJSON - Extract attribute witouth remove it

Super Guru

@Carlos

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()}"
}
3 REPLIES 3

Re: JoltTransformJSON - Extract attribute witouth remove it

Super Guru

@Carlos

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()}"
}

Re: JoltTransformJSON - Extract attribute witouth remove it

Community Manager

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.

Re: JoltTransformJSON - Extract attribute witouth remove it

New Contributor

thanks!! it's works