Json conversion query : Help

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

Json conversion query : Help

Puspak
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/
Reply | Threaded
Open this post in threaded view
|

Re: Json conversion query : Help

Matt Burgess-2
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 <[hidden email]> 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/
Reply | Threaded
Open this post in threaded view
|

Re: Json conversion query : Help

Puspak
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/
Reply | Threaded
Open this post in threaded view
|

Re: Json conversion query : Help

Evan Graham
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 <[hidden email]> 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/
>
Reply | Threaded
Open this post in threaded view
|

Re: Json conversion query : Help

Puspak