Forum Discussion

fajosa's avatar
fajosa
New Contributor II
4 years ago
Solved

Remove json key value from document based on condition

Greetings! Is there a way we can use the mapper to remove “upperlimit” key value from the document, whenever “ApprovalType”==“Greater than equal to” and ignore it if “ApprovalType”==“Between”?? ...
  • j_angelevski's avatar
    j_angelevski
    4 years ago

    Yes, it is possible to map the upperlimit to the lowerlimit, you can try with the following expression:

    jsonPath($, "Project[*]").map(val => val.ApporvalType.toLowerCase() == "greater than equal to" ? val.extend({lowerlimit: val.upperlimit}).filter((v, k) => k != "upperlimit") : val)
    

    Here I’m using the extend() method, with this you can add a specific field to the object or overwrite an existing one with a new value. In this case the upperlimit value will be assigned to the lowerlimit field, resulting in overwrite of that same field.