Home > Blockchain >  how to replace value with constant value in json jolt?
how to replace value with constant value in json jolt?

Time:01-20

input:

{
  "locationId": 100212,
  "weatherDateGmt": 1642590000,
  "geoLocation": {
    "latitude": 43.80306,
    "longitude": 143.89083
  },
  "humidity": 77,
  "currentCondition": "Mostly Clear",
  "latitude": 43.80306,
  "longitude": 143.89083
}

wanted output:

  "locationId": 100212,
  "weatherDateGmt": 1642590000,
  "humidity": 77,
  "currentCondition": "Snow",
  "latitude": 43.80306,
  "longitude": 143.89083

I want the "currentCondition" to be always "Snow" and without geoLocation

here is my jolt:

[
  {
    "operation": "shift",
    "spec": {
      "geoLocation": null,
      "*": "&",
      "currentCondition": {
        "*": { "Snow": "currentCondition" }
      }
    }
  }
]

here is my output:

{
  "locationId" : 100212,
  "weatherDateGmt" : 1642590000,
  "humidity" : 77,
  "latitude" : 43.80306,
  "longitude" : 143.89083
}

the currentCondition has been deleted, how can I fix it?

CodePudding user response:

You can remove those attributes("geoLocation" and "currentCondition") by a remove transformation, then use # notation along with a shift transformation such as

[
  {
    "operation": "remove",
    "spec": {
      "geoLocation": "",
      "currentCondition": ""
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "&",
      "#Snow": "currentCondition"
    }
  }
]

enter image description here

  •  Tags:  
  • Related