Struggling with modification of JSON|AttributeToJSON

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Struggling with modification of JSON|AttributeToJSON

shweta
Hi All,

I have a sample JSON of following format.
{
"a":"1",
"b":"2",
"c":"3",
"d":"4"
}

I have two requirements. First is to split them into two jsons as following:-
{
"a":"1",
"b":"2"
}

and
{
"c":"3",
"d":"4"
}


and my second requirement is to create a nested JSON as following

{"a":"1","info":{"a":"1","b":"2","c":"3","d":"4"}}

I have tried to use the combination of EvaluateJSONPath and AttributeToJSON processor but that did not worked to get the desired output. Can someone please help.

Regards,
Shweta
Reply | Threaded
Open this post in threaded view
|

Re: Struggling with modification of JSON|AttributeToJSON

Joe Percivall
Hello Shweta,

For requirement #1, check out the SplitJson processor. It should enable you to do what you need.

For requirement #2, currently AttributesToJSON can only create flat JSON objects. What you could do is use the ReplaceText processor "manually" do it. You'd leave the search query as the default one (it overwrites the entire content of the flowfile) and then create a replace query that utilizes EL to put the values of attributes where you need them.

Hope that helps,
Joe- - - - - -
Joseph Percivall
linkedin.com/in/Percivall
e: [hidden email]




On Wednesday, February 3, 2016 10:10 AM, shweta <[hidden email]> wrote:
Hi All,

I have a sample JSON of following format.
{
"a":"1",
"b":"2",
"c":"3",
"d":"4"
}

I have two requirements. First is to split them into two jsons as
following:-
{
"a":"1",
"b":"2"
}

and
{
"c":"3",
"d":"4"
}


and my second requirement is to create a nested JSON as following

{"a":"1","info":{"a":"1","b":"2","c":"3","d":"4"}}

I have tried to use the combination of EvaluateJSONPath and AttributeToJSON
processor but that did not worked to get the desired output. Can someone
please help.

Regards,
Shweta



--
View this message in context: http://apache-nifi-developer-list.39713.n7.nabble.com/Struggling-with-modification-of-JSON-AttributeToJSON-tp7129.html
Sent from the Apache NiFi Developer List mailing list archive at Nabble.com.