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.

Need to format values from/in AttributesToJSON processor in Nifi

Need to format values from/in AttributesToJSON processor in Nifi

My AttributesToJSON outputs values this way from a hl7 file after going through ExtractHL7Attributes,

{"PID.PatientName.FamilyName":"Patient","PID.PatientName.GivenName":"Test"}

I want to format the above in this fashion,

"name":[{"family":"Patient","given":"Test"}]

Can it be achieved by using RegEx in properties or through any other processor. Please provide any sample case.

Thanks in advance.

5 REPLIES 5
Highlighted

Re: Need to format values from/in AttributesToJSON processor in Nifi

Highlighted

Re: Need to format values from/in AttributesToJSON processor in Nifi

@Vigneswar Gv Regex probably isn't the right solution here. Instead I'd recommend looking at one of the following:

There are pros and cons to each. Sometimes figuring out the right JOLT specification can be a little tricky but I think this [1] is close to what you're looking for. Solving this with a Groovy script should be pretty straightforward though since you always want to split the keys on the dots. You'll just need a recursive function that iterates through keys, pops off the leading content before the dot and merges it into a sub-entry.

1. https://community.hortonworks.com/questions/137782/nifi-explode-a-json-array-while-keeping-root-leve...

Highlighted

Re: Need to format values from/in AttributesToJSON processor in Nifi

Hi @jfrazee

Thanks for the response. I played around with JoltTransformJSON and was able to transform it from this,

{ "PID.PatientName.FamilyName": "Patient", "PID.PatientName.GivenName": "Test" }

to this,

{ "family": "Patient", "given": "Test" }

The JOLT specification i used was,

[{

"operation": "shift",

"spec": {

"PID.PatientName.FamilyName": "family", "PID.PatientName.GivenName": "given"

}

}]

However i wasn't able to include the part "name" in the json which was end result expected,

"name":[{"family":"Patient","given":"Test"}]

Can you advice of what should be done in JOLT spec to get the desired result ?

@Yolanda M. Davis @Yash

With input attributes like,

{ "PID.PatientName.FamilyName": "Patient", "PID.PatientName.GivenName": "Test", "PID.PhoneNumber.Home": "(123)456789"}

The final JSON formatted output will be looking something like the one below,

{"resourceType":"Patient","identifier":[{"use":"official","system":"urn:fake:mrns","value":"800001","assigner":{"display":"HealthCare Org"}}],"name":[{"family":"Patient","given":"Test12"}],"telecom":[{"system":"phone","value":"111-111-1111","use":"home"}]}
Highlighted

Re: Need to format values from/in AttributesToJSON processor in Nifi

Expert Contributor

I'm not sure why you need an array around the name object - can you explain? Otherwise, you can achieve your desired result by putting "name" in front of your other sub-objects.

[{
"operation": "shift",
"spec": {
"PID.PatientName.FamilyName": "name.family", "PID.PatientName.GivenName": "name.given"
}
}]
Highlighted

Re: Need to format values from/in AttributesToJSON processor in Nifi

New Contributor

@Vigneswar Gv you always can use this debugger before use the processor to make sure it will work OK http://jolt-demo.appspot.com/#prefixSoupToBuckets

Don't have an account?
Coming from Hortonworks? Activate your account here