You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by l vic <lv...@gmail.com> on 2019/03/06 20:18:07 UTC

jolt transform spec ?

I have json message that contains another json message in textual form:
{
"one": "one".
"two":2,
"MSG": "{\"src\":\"my source\",\"priority\":\"0\"}"
}

What would be transform spec to get "contained" message in json ?
{
"src": "my source",
"priority": "0"
}

I've tried the following spec:
[
  {
    "operation": "shift",
    "spec": {
      "MSG": {
        "*": "&"
      }
    }
  }
]
but ended up with just text message:
{ "MSG": "{\"src\":\"my source\",\"priority\":\"0\"}"}
How should i change it?
Thank you

Re: jolt transform spec ?

Posted by l vic <lv...@gmail.com>.
Hi Koji,
Turn out even simpler than that: EvaluateJsonPath to extract it MSG part
into attribute and AttibuteToJson produces normal Json.
Thank you,
Victor

On Wed, Mar 6, 2019 at 8:55 PM Koji Kawamura <ij...@gmail.com> wrote:

> Hello,
>
> I haven't tested myself, but using EvaluateJsonPath and ReplaceText
> with 'unescapeJson' EL function may be an alternative approach instead
> of Jolt.
>
> https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#unescapejson
>
> Idea is, use EvaluateJsonPath to extract the MSG part into a FlowFile
> attribute, e.g. 'message'.
> Then use ReplaceText with 'Replacement Value' as
> "${message:unescapeJson()}" to update FlowFile content with the normal
> JSON representation.
>
> Thanks,
> Koji
>
> On Thu, Mar 7, 2019 at 5:18 AM l vic <lv...@gmail.com> wrote:
> >
> > I have json message that contains another json message in textual form:
> > {
> > "one": "one".
> > "two":2,
> > "MSG": "{\"src\":\"my source\",\"priority\":\"0\"}"
> > }
> >
> > What would be transform spec to get "contained" message in json ?
> > {
> > "src": "my source",
> > "priority": "0"
> > }
> >
> > I've tried the following spec:
> > [
> >   {
> >     "operation": "shift",
> >     "spec": {
> >       "MSG": {
> >         "*": "&"
> >       }
> >     }
> >   }
> > ]
> > but ended up with just text message:
> > { "MSG": "{\"src\":\"my source\",\"priority\":\"0\"}"}
> > How should i change it?
> > Thank you
> >
>

Re: jolt transform spec ?

Posted by Koji Kawamura <ij...@gmail.com>.
Hello,

I haven't tested myself, but using EvaluateJsonPath and ReplaceText
with 'unescapeJson' EL function may be an alternative approach instead
of Jolt.
https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#unescapejson

Idea is, use EvaluateJsonPath to extract the MSG part into a FlowFile
attribute, e.g. 'message'.
Then use ReplaceText with 'Replacement Value' as
"${message:unescapeJson()}" to update FlowFile content with the normal
JSON representation.

Thanks,
Koji

On Thu, Mar 7, 2019 at 5:18 AM l vic <lv...@gmail.com> wrote:
>
> I have json message that contains another json message in textual form:
> {
> "one": "one".
> "two":2,
> "MSG": "{\"src\":\"my source\",\"priority\":\"0\"}"
> }
>
> What would be transform spec to get "contained" message in json ?
> {
> "src": "my source",
> "priority": "0"
> }
>
> I've tried the following spec:
> [
>   {
>     "operation": "shift",
>     "spec": {
>       "MSG": {
>         "*": "&"
>       }
>     }
>   }
> ]
> but ended up with just text message:
> { "MSG": "{\"src\":\"my source\",\"priority\":\"0\"}"}
> How should i change it?
> Thank you
>