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!

Add attribute to json with jolt transform

avatar
Contributor

Hi Everyone,

i would like to add an attribute to the following json file using the jolt transfomr processor. Unfortunately my json file remains unchanged with the following transformation

Original Json File

 

 

{
  "logs": [],
  "ranges": [
    {
      "day": "2022-08-31T22:00:00.000Z",
      "manager": {
        "costByRemunerationId": [],
        "total": 0,
        "totalHours": 0,
        "ancillaryCost": 0
      },
      "crew": {
        "costByRemunerationId": [
          {
            "remunerationId": "salary",
            "remunerationUnit": 2,
            "compensation": 76.66666666666667,
            "worktimeInH": 0,
            "durationInDays": 0,
            "quantity": 0,
            "ancillaryCost": 15.854666666666667
          }
        ],
        "total": 76.66666666666667,
        "totalHours": 0,
        "ancillaryCost": 15.854666666666667
      },
      "trainee": {
        "costByRemunerationId": [],
        "total": 0,
        "totalHours": 0,
        "ancillaryCost": 0
      },
      "apprentice": {
        "costByRemunerationId": [],
        "total": 0,
        "totalHours": 0,
        "ancillaryCost": 0
      },
      "total": 76.66666666666667,
      "totalHours": 0,
      "ancillaryCost": 15.854666666666667
    },
    {
      "day": "2022-09-01T22:00:00.000Z",
      "manager": {
        "costByRemunerationId": [],
        "total": 0,
        "totalHours": 0,
        "ancillaryCost": 0
      },
      "crew": {
        "costByRemunerationId": [
          {
            "remunerationId": "normalHours",
            "remunerationUnit": 0,
            "compensation": 0,
            "worktimeInH": 7.8329297222222225,
            "durationInDays": 2,
            "quantity": 0,
            "ancillaryCost": 0
          },
          {
            "remunerationId": "salary",
            "remunerationUnit": 2,
            "compensation": 76.66666666666667,
            "worktimeInH": 0,
            "durationInDays": 0,
            "quantity": 0,
            "ancillaryCost": 15.854666666666667
          }
        ],
        "total": 76.66666666666667,
        "totalHours": 7.8329297222222225,
        "ancillaryCost": 15.854666666666667
      },
      "trainee": {
        "costByRemunerationId": [],
        "total": 0,
        "totalHours": 0,
        "ancillaryCost": 0
      },
      "apprentice": {
        "costByRemunerationId": [],
        "total": 0,
        "totalHours": 0,
        "ancillaryCost": 0
      },
      "total": 76.66666666666667,
      "totalHours": 7.8329297222222225,
      "ancillaryCost": 15.854666666666667
    }
  ]
}

 

 

 Jolt Transform

 

 

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "target.organisation": "${target.organisation}"
      }
    }
  }
]

 

 

Expected result

{
"logs": [],
"ranges": [
{
"day": "2022-08-31T22:00:00.000Z",
"manager": {
"costByRemunerationId": [],
"total": 0,
"totalHours": 0,
"ancillaryCost": 0
},
"crew": {
"costByRemunerationId": [
{
"remunerationId": "salary",
"remunerationUnit": 2,
"compensation": 76.66666666666667,
"worktimeInH": 0,
"durationInDays": 0,
"quantity": 0,
"ancillaryCost": 15.854666666666667
}
],
"total": 76.66666666666667,
"totalHours": 0,
"ancillaryCost": 15.854666666666667
},
"trainee": {
"costByRemunerationId": [],
"total": 0,
"totalHours": 0,
"ancillaryCost": 0
},
"apprentice": {
"costByRemunerationId": [],
"total": 0,
"totalHours": 0,
"ancillaryCost": 0
},
"total": 76.66666666666667,
"totalHours": 0,
"ancillaryCost": 15.854666666666667
},
{
"day": "2022-09-01T22:00:00.000Z",
"manager": {
"costByRemunerationId": [],
"total": 0,
"totalHours": 0,
"ancillaryCost": 0
},
"crew": {
"costByRemunerationId": [
{
"remunerationId": "normalHours",
"remunerationUnit": 0,
"compensation": 0,
"worktimeInH": 7.8329297222222225,
"durationInDays": 2,
"quantity": 0,
"ancillaryCost": 0
},
{
"remunerationId": "salary",
"remunerationUnit": 2,
"compensation": 76.66666666666667,
"worktimeInH": 0,
"durationInDays": 0,
"quantity": 0,
"ancillaryCost": 15.854666666666667
}
],
"total": 76.66666666666667,
"totalHours": 7.8329297222222225,
"ancillaryCost": 15.854666666666667
},
"trainee": {
"costByRemunerationId": [],
"total": 0,
"totalHours": 0,
"ancillaryCost": 0
},
"apprentice": {
"costByRemunerationId": [],
"total": 0,
"totalHours": 0,
"ancillaryCost": 0
},
"total": 76.66666666666667,
"totalHours": 7.8329297222222225,
"ancillaryCost": 15.854666666666667
}
],

"target.organisation": myorganisation 
}

Thanks for idea what is still missing from my query

1 ACCEPTED SOLUTION

avatar
Super Guru

Hi,

 

I dont think you need the asterisk "*" in the spec, since you need it on the first level and you dont need to reference any other fields. Just have your spec as follows:

 

 

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "target.organisation": "${target.organisation}"
    }
  }
]

 

 

 

View solution in original post

1 REPLY 1

avatar
Super Guru

Hi,

 

I dont think you need the asterisk "*" in the spec, since you need it on the first level and you dont need to reference any other fields. Just have your spec as follows:

 

 

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "target.organisation": "${target.organisation}"
    }
  }
]