Forum Discussion

adityamohanty's avatar
adityamohanty
New Contributor II
3 years ago
Solved

How to rename a column in a single expression without impacting the other columns in a json file

My source data looks like this. I want to rename "Emp.Type" column to "EmpType" in a single expression without impacting the other columns in json file. I don't want to use column map in mapper where...
  • alchemiz's avatar
    3 years ago

    Hi adityamohanty ,

    Good day, you can use mapKeys or string manipulation

    ** only top level keyname will be updated
    $.mapKeys((val,key)=> key == 'Emp.Type' ? 'EmpType' : key)


    ** global, replace all matching Emp.Type string to EmpType
    JSON.parse(JSON.stringify($).replace(/Emp.Type/gm, m => match m {'Emp.Type'=> 'EmpType'}))

    ~EmEm