skip to Main Content

I’m trying to use replace function to remove the special characters, but the escape characters are not being removed.

Input:

[
  {
    "MiddleName": "Gisela"mn"
  },
  {
    "MiddleName": "Gisela12---"
  }
]

Spec:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "MiddleName": "=replace('(\-\s*)|\s+--',@(1,MiddleName))"
      }
    }
  }
]

The output I’m getting:

[
  {
    "MiddleName": "Gisela"mn"
  },
  {
    "MiddleName": "Gisela12"
  }
]

The output I need:

[
  {
    "MiddleName": "Giselamn"
  },
  {
    "MiddleName": "Gisela12"
  }
]

2

Answers


  1. You can consecutively use split and join functions such as

    [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": {
            "*": "=split('"',@(1,&))"
          }
        }
      },
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": {
            "*": "=join('',@(1,&))"
          }
        }
      },
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": {
            "*": "=split('-',@(1,&))"
          }
        }
      },
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": {
            "*": "=join('',@(1,&))"
          }
        }
      }
    ]
    
    Login or Signup to reply.
  2. You can use simpler way like this spec:

    [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "*": {
            "MiddleName_temp1": "=split('"',@(1,MiddleName))",
            "MiddleName_temp2": "=join('',@(1,MiddleName_temp1))",
            "MiddleName_temp3": "=split('-',@(1,MiddleName_temp2))",
            "MiddleName": "=join('',@(1,MiddleName_temp3))"
          }
        }
      },
      {
        "operation": "remove",
        "spec": {
          "*": {
            "MiddleName*": ""
          }
        }
      }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search