Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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

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

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