Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Need Help with Jolt Transformation - Stuck for Days

avatar
Frequent Visitor

Hii Everyone,

I've been struggling to achieve the desired result with a Jolt transformation for the past few days and could really use some help from the community.

input.json:

 

{
  "email": "[email protected]",
  "dates": [
    {
      "date": "2023-12-01",
      "type": "full"
    },
    {
      "date": "2023-11-03",
      "type": "full"
    },
    {
      "date": "2023-11-02",
      "type": "full"
    },
    {
      "date": "2023-10-01",
      "type": "half"
    }
  ]
}

 

output.json

 

[
  {
    "emailId": "[email protected]",
    "date": "2023-12-01",
    "type": "full"
  },
  {
    "emailId": "[email protected]",
    "date": "2023-11-03",
    "type": "full"
  },
  {
    "emailId": "[email protected]",
    "date": "2023-11-02",
    "type": "full"
  },
  {
    "emailId": "[email protected]",
    "date": "2023-10-01",
    "type": "half"
  }
]

 

spec file for the transformation:

 

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "email": "[].emailId",
        "dates": {
          "*": {
            "date": "[&1].date",
            "type": "[&1].type"
          }
        }
      }
    }
  }
]

 

Despite my efforts, I'm not achieving the expected outcome. Can anyone please review my Jolt specification and provide insights on what might be going wrong? Your assistance is highly appreciated.

Thank you in advance!

1 ACCEPTED SOLUTION

avatar
Super Guru

Hi @Eva0 ,

You were close . I think the first astrik "*" was  not needed because the input json is not contained in an array brackets. Then to include the email in each data element it has to be added at the date & type level but to reference the value you need to go to 2 levels up using the @ character as in @(2,mail) where the email is located in relative to date & type.

[
  {
    "operation": "shift",
    "spec": {
      //level 2 where email originally is
      "dates": {
        // level 1
        "*": { 
          // start count here at level 0 
          "@(2,email)": "[&1].email",
          "date": "[&1].date",
          "type": "[&1].type"
        }
      }
    }
  }
  ]

If you find this helpful please accept solution.

Thanks

View solution in original post

2 REPLIES 2

avatar
Community Manager

@Eva0, Welcome to our community! To help you get the best possible answer, I have tagged our NiFi experts @MattWho @TimothySpann @cotopaul @SAMSAL  who may be able to assist you further.

Please feel free to provide any additional information or details about your query, and we hope that you will find a satisfactory solution to your question.



Regards,

Vidya Sargur,
Community Manager


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:

avatar
Super Guru

Hi @Eva0 ,

You were close . I think the first astrik "*" was  not needed because the input json is not contained in an array brackets. Then to include the email in each data element it has to be added at the date & type level but to reference the value you need to go to 2 levels up using the @ character as in @(2,mail) where the email is located in relative to date & type.

[
  {
    "operation": "shift",
    "spec": {
      //level 2 where email originally is
      "dates": {
        // level 1
        "*": { 
          // start count here at level 0 
          "@(2,email)": "[&1].email",
          "date": "[&1].date",
          "type": "[&1].type"
        }
      }
    }
  }
  ]

If you find this helpful please accept solution.

Thanks