Support Questions

Find answers, ask questions, and share your expertise

Jolt Transform spec

avatar
New Contributor

I am trying to understand simple jolt transformations 

My original json 

{

  "name" : "john",

  "Address2" : "123 Street 1",

  "Address1" : "Apt 101",

  "custId" : "ZY-1234",

  "zip" : "67834" 

}

 

I would like to change the sequence of columns and get comma separated values with default tags added to it, like below

The last column value should be defaulted to current datetime

{

   "Rows" : [

         { "values" : [ "ZY-1234" , "john" , "123 Street 1","Apt 101","67834","2022-09-01 10:10:09" ] }

  ],

  "operationType" : "Insert",

  "Source" : "Dev"

}

here is the Spec I got to 

[
{
"operation": "default",
"spec": {
"ChangedBy": "NIFI",
"ChangedOn": "${now()}"
}
},
{
"operation": "shift",
"spec": {
"*": {
"@": "Rows[#1].Value"
}
}
},
{
"operation": "default",
"spec": {
"*": {
"*": "&"
},
"operationType": "Insert",
"Source": "Dev"
}
}

]

 

The Result of this 

{
"Rows" : [ {
"Values" : [ "john", "123 Street 1", "Apt 101", "ZY-1234", "67834", "NIFI", "${now()}" ]
} ],
"operationType" : "Insert",
"Source" : "Dev"
}

Issues : 

1. How to change the column sequence in Values array
2. How to get current datetime

 

2 REPLIES 2

avatar
Super Guru

@VenkatG ,

 

What are you trying to use this resulting JSON for? That seems a bit odd of a format to me.

Nevertheless, here's a JOLT to achieve that (or close):

[
  {
    "operation": "default",
    "spec": {
      "__timestamp": "${now()}"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "custId": "Rows[0].values[0]",
      "name": "Rows[0].values[1]",
      "Address2": "Rows[0].values[2]",
      "Address1": "Rows[0].values[3]",
      "zip": "Rows[0].values[4]",
      "__timestamp": "Rows[0].values[5]"
    }
  },
  {
    "operation": "default",
    "spec": {
      "operationType": "Insert",
      "Source": "Dev"
    }
  }
]

 

Cheers,

André

 

--
Was your question answered? Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs up button.

avatar
Community Manager

@VenkatG Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future. Thanks


Regards,

Diana Torres,
Community Moderator


Was your question answered? Make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.
Learn more about the Cloudera Community: