Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to replace value with constant value in json jolt?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading