how to replace the underscore "_" at the end of a dict key?

Viewed 53

I revoked an HTTP request the response is a list of JSON records [{},{},{}] within those records we have some keys with an "_" at the end.

[
  {
    "name": "json",
    "surname": "file",
    "which_extention_": "json",
    "size_of_file_": "266"
  },
  {},
  {}
]

It needs to look like that:

[
  {
    "name": "json",
    "surname": "file",
    "which_extention": "json",
    "size_of_file": "266"
  },
  {},
  {}
]

I tried to use ReplaceText with the regex : [_$]$ and with this _$ but doesn't work.

2 Answers

You can add a JoltTransformJSON processor with shift transformation spec such as

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*_": "[&1].&(0,1)",//"*_" represents the keys of the attributes ending with "_"
        "*": "[&1].&"       //this whole line stands for the rest of the attributes
      }
    }
  }
]

the demo on the site http://jolt-demo.appspot.com/ is

enter image description here

Your regex doesn't seem correct, you don't need two end anchor $. Try this regex _$ instead. It matches _ character at the end.

Related