Created 04-27-2020 10:30 PM
Hi All,
I have single JSON object in a flow file. I just want to append and prepend text to it, and pass it over as flowfiles for subsequent processors. Here is what I want to achieve:
Input FlowFile Content:
{ "first_name": "alpha", "age": "30" }
Expected output in FlowFile Content:
{ $set: { "first_name": "alpha", "age": "30" } }
So basically i want to prepend "{ $set " and append " } "
I found crude way of updating it, in multiple steps. But just wanted to do it in proper and concise manner.
Created on 04-28-2020 04:49 AM - edited 04-28-2020 04:52 AM
@arunnalpet This sounds like a perfect job for ReplaceText:
I did notice that you have set as $set. In order to maintain a real json object, I have used just "set". The set object is available as $.set if you use EvalateJsonPath. If you still need $set, please explain...
Below is the configuration you need for ReplaceText. It regex matches the entire flow file then adds the prepend before $1 and adds the append after.
{ "set" : $1 }
(this is the only change in the processors from default)
And the output:
{ "set" : { "first_name": "alpha", "age": "30" } }
Created 05-03-2020 11:41 PM
Thank you! This gives me some directions.
One thing though is that, i really want it to be "$set" and I am not expecting it to comply to JSON standard after doing this.
So I guess i can just use $set in the replacement value and get the job done. (i think we need to escape $ value). Will try it out and get back.
Created on 05-04-2020 07:40 AM - edited 05-04-2020 07:42 AM
@arunnalpet yes that is correct. I wanted to avoid $set in basic testing and also advocating for valid code practice to avoid issues further with the data source.
If the answer above resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.
Thanks,
Created 05-18-2020 03:50 AM
Hi,
Actually I am working on MongoDB queries, which supports 'Extended JSON' as opposed to 'Standard JSON'. For which I need to enforce $set. Is there a way we can implement this?
Created 05-18-2020 05:34 AM
@arunnalpet You should be able to just add the $. If it doesn't work, maybe have to escape it: \$