Support Questions

Find answers, ask questions, and share your expertise
Announcements
Check out our newest addition to the community, the Cloudera Data Analytics (CDA) group hub.

Add attribute to json with jolt transform

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

Super Collaborator

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

Super Collaborator

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}"
    }
  }
]

 

 

 

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.