skip to Main Content

I am trying to mask/hide a value of a field in a json file.

I have json that looks something like this:

    "PLUSDATA": {
        "global": {
            "auth_type": "login", 
            "passkey": "SENSETIVE_CONTENT_TO_BE_HIDDEN", 
            "src_intf": "Loopback0", 
            "timeout": "5"
        }
    }, 

I’d like to parse my json and have the "SENSETIVE_CONTENT_TO_BE_HIDDEN" masked with * ( length does not matter

    "PLUSDATA": {
        "global": {
            "auth_type": "login", 
            "passkey": "****", 
            "src_intf": "Loopback0", 
            "timeout": "5"
        }
    }, 

Thank you,

I am trying some variations of awk/sed but just can’t get the desired result.

2

Answers


  1. Chosen as BEST ANSWER

    I was able to get part of sed working when given a concrete line:

    echo '{"passkey":"sensetive_cotnent"}' | sed 's/({"passkey":")[^"]*("})/1xxxxxxxxxxx2/g'
    

    which parses it correctly.

    But i can't seem to get the same result when doing something like:

    cat my_sensetive_file.json | sed 's/({"passkey":")[^"]*("})/1xxxxxxxxxxx2/g'
    

  2. $ jq -r '.PLUSDATA.global.passkey = "******"' file.json
    {
      "PLUSDATA": {
        "global": {
          "auth_type": "login",
          "passkey": "******",
          "src_intf": "Loopback0",
          "timeout": "5"
        }
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search