You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nifi.apache.org by Puspak <pu...@gmail.com> on 2019/05/25 01:09:00 UTC

Json conversion query : Help

hi , i have a requirement where i have to convert json 1 to json 2 . Could
you please suggest how can i achieve it  nifi .

json1 - 
{
  "somedate" : "1557840900",
}
json2-
{
  "somedate" : {
    "$date" : 1557840900
  }
}

which kind of transformation i can use for the same.



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/

Re: Json conversion query : Help

Posted by Puspak <pu...@gmail.com>.
Thank you



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/

Re: Json conversion query : Help

Posted by Evan Graham <lu...@gmail.com>.
This should do what you need:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "eta": "=toLong",
      "etd": "=toLong"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "eta": "&.\\$date",
      "etd": "&.\\$date",
      "*": "&"
    }
  }
]

It will convert eta and etd to longs, then the shift operation is pretty
much as Matt posted but with the extra field added.

Thanks

On Sat, May 25, 2019 at 3:48 AM Puspak <pu...@gmail.com> wrote:

> Thanks Matt for such a quick response,
>
> This perfectly works for the above scenario .
> But my requirement is little different . I tried to implement the same in
> my
> case but failed .Could you please suggest . This is because I am relatively
> new to jolt.
>
> input :
> {
>   "eta" : "1557840900",
>   "actualdeparturetime" : "0",
>   "etd" : "1557835200",
>   "ident" : "JST529",
>   "FlightNumber" : "529",
>   "CarrierCode" : "JQ",
>   "actualarrivaltime" : "1557840900",
>   "startDate" : "1557772200"
> }
> output :
> {
>   "ident" : "JST529",
>   "eta" : {
>     "$date" : 1557840900000
>   },
>   "actualdeparturetime" : "0",
>   "etd" : {
>     "$date" : 1557835200000
>   },
>   "messageType" : "FFM",
>   "FlightNumber" : "529",
>   "CarrierCode" : "JQ",
>   "actualarrivaltime" : "0",
>   "startDate" : "1557772200"
> }
>
> that means basically the json has some other few fields as well
>
>
>
> --
> Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/
>

Re: Json conversion query : Help

Posted by Puspak <pu...@gmail.com>.
Thanks Matt for such a quick response,

This perfectly works for the above scenario .
But my requirement is little different . I tried to implement the same in my
case but failed .Could you please suggest . This is because I am relatively
new to jolt.

input : 
{
  "eta" : "1557840900",
  "actualdeparturetime" : "0",
  "etd" : "1557835200",
  "ident" : "JST529",
  "FlightNumber" : "529",
  "CarrierCode" : "JQ",
  "actualarrivaltime" : "1557840900",
  "startDate" : "1557772200"
}
output :
{
  "ident" : "JST529",
  "eta" : {
    "$date" : 1557840900000
  },
  "actualdeparturetime" : "0",
  "etd" : {
    "$date" : 1557835200000
  },
  "messageType" : "FFM",
  "FlightNumber" : "529",
  "CarrierCode" : "JQ",
  "actualarrivaltime" : "0",
  "startDate" : "1557772200"
}

that means basically the json has some other few fields as well 



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/

Re: Json conversion query : Help

Posted by Matt Burgess <ma...@apache.org>.
Try this spec:

[
  {
    "operation": "shift",
    "spec": {
      "somedate": "somedate.\\$date"
    }
  }
]

I haven't tried this in NiFi (only in http://jolt-demo.appspot.com),
if there's an issue with Expression Language you might need to escape
more of the $ somehow.

Regards,
Matt

On Fri, May 24, 2019 at 9:11 PM Puspak <pu...@gmail.com> wrote:
>
> hi , i have a requirement where i have to convert json 1 to json 2 . Could
> you please suggest how can i achieve it  nifi .
>
> json1 -
> {
>   "somedate" : "1557840900",
> }
> json2-
> {
>   "somedate" : {
>     "$date" : 1557840900
>   }
> }
>
> which kind of transformation i can use for the same.
>
>
>
> --
> Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/