Tuesday, February 18, 2025
HomeGolangDiscover keys and change corresponding values utilizing Regex - Getting Assist

Discover keys and change corresponding values utilizing Regex – Getting Assist


Hello,

How do we discover and change a bit in a string with regex utilizing lookahead/lookbehind or one thing comparable?

I’ve a nested json and need to discover sure keys and change corresponding values with REPLACED.

Be aware: I’m not excited by JSON marshal/unmarshal/encode/decode options.

Thanks

Have

{
  "standing": 200,
  "outcome": {
    "username": "john",
    "password": "Pa55w0rd",
    "eastings": 13452,
    "northings": 945,
    "admin": null,
    "codes": {
      "client_id": "E090000",
      "client_secret": "E119999",
      "ward": "W1"
    }
  }
}

WANT

{
  "standing": 200,
  "outcome": {
    "username": "REPLACED",
    "password": "REPLACED",
    "eastings": 13452,
    "northings": 945,
    "admin": null,
    "codes": {
      "client_id": "REPLACED",
      "client_secret": "REPLACED",
      "ward": "W1"
    }
  }
}

I like to recommend you to make use of gjson and sjson for json modifying.
Or you’ll be able to convert the json right into a map, edit it after which convert it again into json.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments