You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by "Jens M. Kofoed" <jm...@gmail.com> on 2020/09/25 05:48:07 UTC
How to split json subarrays and keep root
Hi
I have a JSON document with an array which I would like to split and
flatten.
In my example below key4 is an array containing 2 documents. I need to
split the record based on each document in the key4 array, so I end up with
multiple records. Where each new record has a copy of all keys except key4
which should be flatten into each own document.
{
key1:value1,
key2:value2,
key3: {
key3a:value3a,
key3b:value3b
}
key4: [
{
key4a1:value4a1,
key4a2:value4a2
},
{
key4b1:value4b1,
key4b2:value4b2
}
]
}
Should be like this:
Record 1
{
key1:value1,
key2:value2,
key3: {
key3a:value3a,
key3b:value3b
}
key4:{
key4a1:value4a1,
key4a2:value4a2
}
}
Record 2
{
key1:value1,
key2:value2,
key3: {
key3a:value3a,
key3b:value3b
}
key4:{
key4b1:value4b1,
key4b2:value4b2
}
}
Kind regards
Jens M. Kofoed
Re: How to split json subarrays and keep root
Posted by "Jens M. Kofoed" <jm...@gmail.com>.
Hi Matt
Thank you very much for pointing me to the ForkRecord. After playing around
with it I got to work.
kind regards
Jens
Den man. 28. sep. 2020 kl. 23.37 skrev Matt Burgess <ma...@apache.org>:
> Jens,
>
> Try ForkRecord [1] with "Mode" set to "Extract" and "Include Parent
> Fields" set to "true", I think that does what you're looking to do.
>
> Regards,
> Matt
>
> [1]
> https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.12.1/org.apache.nifi.processors.standard.ForkRecord/index.html
>
> On Fri, Sep 25, 2020 at 1:48 AM Jens M. Kofoed <jm...@gmail.com>
> wrote:
> >
> > Hi
> >
> > I have a JSON document with an array which I would like to split and
> flatten.
> > In my example below key4 is an array containing 2 documents. I need to
> split the record based on each document in the key4 array, so I end up with
> multiple records. Where each new record has a copy of all keys except key4
> which should be flatten into each own document.
> > {
> > key1:value1,
> > key2:value2,
> > key3: {
> > key3a:value3a,
> > key3b:value3b
> > }
> > key4: [
> > {
> > key4a1:value4a1,
> > key4a2:value4a2
> > },
> > {
> > key4b1:value4b1,
> > key4b2:value4b2
> > }
> > ]
> > }
> >
> > Should be like this:
> > Record 1
> > {
> > key1:value1,
> > key2:value2,
> > key3: {
> > key3a:value3a,
> > key3b:value3b
> > }
> > key4:{
> > key4a1:value4a1,
> > key4a2:value4a2
> > }
> > }
> >
> > Record 2
> > {
> > key1:value1,
> > key2:value2,
> > key3: {
> > key3a:value3a,
> > key3b:value3b
> > }
> > key4:{
> > key4b1:value4b1,
> > key4b2:value4b2
> > }
> > }
> >
> > Kind regards
> > Jens M. Kofoed
>
Re: How to split json subarrays and keep root
Posted by Matt Burgess <ma...@apache.org>.
Jens,
Try ForkRecord [1] with "Mode" set to "Extract" and "Include Parent
Fields" set to "true", I think that does what you're looking to do.
Regards,
Matt
[1] https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.12.1/org.apache.nifi.processors.standard.ForkRecord/index.html
On Fri, Sep 25, 2020 at 1:48 AM Jens M. Kofoed <jm...@gmail.com> wrote:
>
> Hi
>
> I have a JSON document with an array which I would like to split and flatten.
> In my example below key4 is an array containing 2 documents. I need to split the record based on each document in the key4 array, so I end up with multiple records. Where each new record has a copy of all keys except key4 which should be flatten into each own document.
> {
> key1:value1,
> key2:value2,
> key3: {
> key3a:value3a,
> key3b:value3b
> }
> key4: [
> {
> key4a1:value4a1,
> key4a2:value4a2
> },
> {
> key4b1:value4b1,
> key4b2:value4b2
> }
> ]
> }
>
> Should be like this:
> Record 1
> {
> key1:value1,
> key2:value2,
> key3: {
> key3a:value3a,
> key3b:value3b
> }
> key4:{
> key4a1:value4a1,
> key4a2:value4a2
> }
> }
>
> Record 2
> {
> key1:value1,
> key2:value2,
> key3: {
> key3a:value3a,
> key3b:value3b
> }
> key4:{
> key4b1:value4b1,
> key4b2:value4b2
> }
> }
>
> Kind regards
> Jens M. Kofoed