-1

I have following JSON data, from which I want to remove the parentheses using Jolt:

Input

{
  "tID": "8934894",
  "deviceData": {
    "tID": "8934894",
    "active": true,
    "status": "activated",
    "name": "pqr"
  },
  "C": 132,
  "nameData": [
    {
      "name": "Anopheles subpictus (Malaria)",
      "nameWiseCount": 1,
      "genderWiseData": [
        {
          "gender": "Female",
          "genderWiseCount": 1
        }
      ]
    },
    {
      "name": "Aedes albopictus (Dengue/Chikungunya/Zika )",
      "nameWiseCount": 41,
      "genderWiseData": [
        {
          "gender": "Male",
          "genderWiseCount": 15
        },
        {
          "gender": "Female",
          "genderWiseCount": 26
        }
      ]
    },
    {
      "name": "UnIdentified (NA)",
      "nameWiseCount": 297,
      "genderWiseData": [
        {
          "gender": "Male",
          "genderWiseCount": 297
        }
      ]
    },
    {
      "name": "Culex quinquefasciatus (Filariasis)",
      "nameWiseCount": 1162,
      "genderWiseData": [
        {
          "gender": "Male",
          "genderWiseCount": 619
        },
        {
          "gender": "Female",
          "genderWiseCount": 543
        }
      ]
    },
    {
      "name": "Armigeres subalbatus (Nuisance)",
      "nameWiseCount": 190,
      "genderWiseData": [
        {
          "gender": "Male",
          "genderWiseCount": 121
        },
        {
          "gender": "Female",
          "genderWiseCount": 69
        }
      ]
    }
  ]
}

The nameData array contain list of data and all the contain a key name. The value of name contain special character "()" . I want to remove this special character by jolt processor

Expected output

{
  "tID": "8934894",
  "deviceData": {
    "tID": "8934894",
    "active": true,
    "status": "activated",
    "name": "pqr"
  },
  "C": 132,
  "nameData": [
    {
      "name": "Anopheles subpictus Malaria",
      "nameWiseCount": 1,
      "genderWiseData": [
        {
          "gender": "Female",
          "genderWiseCount": 1
        }
      ]
    },
    {
      "name": "Aedes albopictus Dengue/Chikungunya/Zika",
      "nameWiseCount": 41,
      "genderWiseData": [
        {
          "gender": "Male",
          "genderWiseCount": 15
        },
        {
          "gender": "Female",
          "genderWiseCount": 26
        }
      ]
    },
    {
      "name": "UnIdentified (NA)",
      "nameWiseCount": 297,
      "genderWiseData": [
        {
          "gender": "Male",
          "genderWiseCount": 297
        }
      ]
    },
    {
      "name": "Culex quinquefasciatus Filariasis",
      "nameWiseCount": 1162,
      "genderWiseData": [
        {
          "gender": "Male",
          "genderWiseCount": 619
        },
        {
          "gender": "Female",
          "genderWiseCount": 543
        }
      ]
    },
    {
      "name": "Armigeres subalbatus Nuisance",
      "nameWiseCount": 190,
      "genderWiseData": [
        {
          "gender": "Male",
          "genderWiseCount": 121
        },
        {
          "gender": "Female",
          "genderWiseCount": 69
        }
      ]
    }
  ]
}

For example, if the name is "Armigeres subalbatus (Nuisance)". I want to remove the parentheses, (). I need it to output Armigeres subalbatus Nuisance.

How can I remove parentheses in JSON data using Jolt?

Adriaan
  • 17,741
  • 7
  • 42
  • 75
neeraj
  • 11
  • 2
  • Welcome to Stack Overflow! Thank you for your input and expected output. It is however appreciated that you also show what you've already tried to solve this problem yourself. Code, in the from of a [mre] would be great, but also research or thoughts on how to do this are good. Without effort from your part, whilst within the rules, you stand much less of a chance to receive good answers. – Adriaan Aug 25 '22 at 11:33
  • Those brackets still remain for `UnIdentified (NA)` ...? – Barbaros Özhan Aug 25 '22 at 11:38

1 Answers1

0

You can apply split and then join within modify transformations twice in order to remove ( and then ) step by step such as

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "name*": {
        "*": {
          "name": "=split('\\(', @(1,&))"
        }
      }
    }
  },
  {
   // the "(" characters are removed now 
    "operation": "modify-overwrite-beta",
    "spec": {
      "name*": {
        "*": {
          "name": "=join('', @(1,&))"
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "name*": {
        "*": {
          "name": "=split('\\)', @(1,&))"
        }
      }
    }
  },
  {
   // the ")" characters are removed now 
    "operation": "modify-overwrite-beta",
    "spec": {
      "name*": {
        "*": {
          "name": "=join('', @(1,&))"
        }
      }
    }
  }
]
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55