You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by Sven Davison <sv...@gmail.com> on 2016/06/01 17:10:42 UTC
getFile Content as json element
i've got a flow where i'm reading a file and setting various attributes.
now i want to wrap the content of the origional file into a "content"
element w/in my JSON object.
this is invalid json but you'll get the idea.
{ filename: "somefile",
fileTime: blahSomeDateString
content:[
need content from origional file here.
]
}
right now i can get eaither the content.. OR the other properties. How do i
combine them?!
-Sven
Re: getFile Content as json element
Posted by Mark Payne <ma...@hotmail.com>.
Sven,
With Regex, I forgot that the . character does not match end-of-line characters. So you'll end up with the output like
you described below. You should be okay, though, if you change the regex to (?s:.+)
This indicates that you want to use "dot-all" mode so that the . character will match end-of-line characters as well.
Thanks
-Mark
> On Jun 2, 2016, at 10:22 AM, Sven Davison <sv...@gmail.com> wrote:
>
> I tried this yesterday.. tried a couple diffrent things. it looks like it's doing it line by line instead of as a batch.. so if i have 3 lines in my file i have something like this.
>
> {
> filename: "${filename}",
> fileTime: ${now()},
> content: [
> first line of file
> ]
> }
>
>
> {
> filename: "${filename}",
> fileTime: ${now()},
> content: [
> second line of file
> ]
> }
>
>
> {
> filename: "${filename}",
> fileTime: ${now()},
> content: [
> third line of file
> ]
> }
>
>
> On Wed, Jun 1, 2016 at 2:02 PM, Mark Payne <markap14@hotmail.com <ma...@hotmail.com>> wrote:
> Sven,
>
> Have you had a look at the ReplaceText processor? You could use the Regular Expression (.+) to match the entire content
> of the FlowFile and then replace it with something like:
>
> {
> filename: "${filename}",
> fileTime: ${now()},
> content: [
> $1
> ]
> }
>
> The $1 is a back-reference that will reference whatever is in the first capturing group of your Regular Expression (in this case,
> the entire content of the FlowFile).
>
> Thanks
> -Mark
>
>
> > On Jun 1, 2016, at 1:10 PM, Sven Davison <svendavison@gmail.com <ma...@gmail.com>> wrote:
> >
> > i've got a flow where i'm reading a file and setting various attributes. now i want to wrap the content of the origional file into a "content" element w/in my JSON object.
> >
> > this is invalid json but you'll get the idea.
> >
> > { filename: "somefile",
> > fileTime: blahSomeDateString
> > content:[
> > need content from origional file here.
> > ]
> > }
> >
> >
> > right now i can get eaither the content.. OR the other properties. How do i combine them?!
> >
> >
> >
> > -Sven
>
>
Re: getFile Content as json element
Posted by Sven Davison <sv...@gmail.com>.
I tried this yesterday.. tried a couple diffrent things. it looks like it's
doing it line by line instead of as a batch.. so if i have 3 lines in my
file i have something like this.
{
filename: "${filename}",
fileTime: ${now()},
content: [
first line of file
]
}
{
filename: "${filename}",
fileTime: ${now()},
content: [
second line of file
]
}
{
filename: "${filename}",
fileTime: ${now()},
content: [
third line of file
]
}
On Wed, Jun 1, 2016 at 2:02 PM, Mark Payne <ma...@hotmail.com> wrote:
> Sven,
>
> Have you had a look at the ReplaceText processor? You could use the
> Regular Expression (.+) to match the entire content
> of the FlowFile and then replace it with something like:
>
> {
> filename: "${filename}",
> fileTime: ${now()},
> content: [
> $1
> ]
> }
>
> The $1 is a back-reference that will reference whatever is in the first
> capturing group of your Regular Expression (in this case,
> the entire content of the FlowFile).
>
> Thanks
> -Mark
>
>
> > On Jun 1, 2016, at 1:10 PM, Sven Davison <sv...@gmail.com> wrote:
> >
> > i've got a flow where i'm reading a file and setting various attributes.
> now i want to wrap the content of the origional file into a "content"
> element w/in my JSON object.
> >
> > this is invalid json but you'll get the idea.
> >
> > { filename: "somefile",
> > fileTime: blahSomeDateString
> > content:[
> > need content from origional file here.
> > ]
> > }
> >
> >
> > right now i can get eaither the content.. OR the other properties. How
> do i combine them?!
> >
> >
> >
> > -Sven
>
>
Re: getFile Content as json element
Posted by Mark Payne <ma...@hotmail.com>.
Sven,
Have you had a look at the ReplaceText processor? You could use the Regular Expression (.+) to match the entire content
of the FlowFile and then replace it with something like:
{
filename: "${filename}",
fileTime: ${now()},
content: [
$1
]
}
The $1 is a back-reference that will reference whatever is in the first capturing group of your Regular Expression (in this case,
the entire content of the FlowFile).
Thanks
-Mark
> On Jun 1, 2016, at 1:10 PM, Sven Davison <sv...@gmail.com> wrote:
>
> i've got a flow where i'm reading a file and setting various attributes. now i want to wrap the content of the origional file into a "content" element w/in my JSON object.
>
> this is invalid json but you'll get the idea.
>
> { filename: "somefile",
> fileTime: blahSomeDateString
> content:[
> need content from origional file here.
> ]
> }
>
>
> right now i can get eaither the content.. OR the other properties. How do i combine them?!
>
>
>
> -Sven