Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How can I append key:value to a json flowfile ?

avatar
Explorer

Hello,

I am trying to add key: value in a json after SplitJSON. I was using ReplaceText processor for achieving so. But problem my regex expr is coming twice my json object which causing the invalid json. What would be the appropriate way to do so ?

Current Structure:

piyush7829_0-1709537210554.png

Replace Text Processor looks like :

piyush7829_1-1709537244937.png

Any suggestions will be of great help!!

1 ACCEPTED SOLUTION

avatar

Hi @piyush7829 ,

Why dont you do that using JoltTransformation as well. I think you can do it before split or after depending what is the json is and what is the expected new output. JsonJoltTransformation  processor is very powerful and it allows you to use Expression Language which mean you can reference attributes in the jolt spec and assign them to new key. For example if you want to assign the value of the attribute ${series_id} to new key called series_id , then in jolt spec you can do that as follows:

[
  {
    "operation": "shift",
    "spec": { 
                .....
   	       "#${series_id}":"series_id"
                ......
    }
  }
]

If you need help with the jolt spec please post sample input and expected output and I will he happy to help you.

If you find this is helpful please accept solution.

Thanks

 

View solution in original post

1 REPLY 1

avatar

Hi @piyush7829 ,

Why dont you do that using JoltTransformation as well. I think you can do it before split or after depending what is the json is and what is the expected new output. JsonJoltTransformation  processor is very powerful and it allows you to use Expression Language which mean you can reference attributes in the jolt spec and assign them to new key. For example if you want to assign the value of the attribute ${series_id} to new key called series_id , then in jolt spec you can do that as follows:

[
  {
    "operation": "shift",
    "spec": { 
                .....
   	       "#${series_id}":"series_id"
                ......
    }
  }
]

If you need help with the jolt spec please post sample input and expected output and I will he happy to help you.

If you find this is helpful please accept solution.

Thanks