Redacting Sensitive Data From Text Content

You can use the code samples below to redact sensitive data from a string of text. You can also feed information to the API using JSON over HTTP.

The API takes the following as arguments:

  • A string of text
  • The placeholder text that will replace sensitive data (in this example, "REDACTED")
  • A list of one or more infoTypes that you want to redact

It returns the string with any sensitive data replaced by your chosen placeholder.

Example text redaction

See the JSON quickstart for more information on using JSON.

Sample Input:

{
  "item": {
     "value":"My email is test@gmail.com",
   },
   "deidentifyConfig": {
     "infoTypeTransformations":{
          "transformations": [
            {
              "primitiveTransformation": {
                "replaceWithInfoTypeConfig": {}
              }
            }
          ]
        }
    },
    "inspectConfig": {
      "infoTypes": {
        "name": "EMAIL_ADDRESS"
      }
    }
}

URL:

  POST https://dlp.googleapis.com/v2/projects/project-id/content:deidentify

Sample Output:

{
"item": {
  "value": "My email is [EMAIL_ADDRESS]"
},
"overview": {
  "transformedBytes": 14,
  "transformationSummaries": {
    "infoType": {
      "name": "EMAIL_ADDRESS"
    },
    "transformation": {
      "replaceWithInfoTypeConfig": {
      }
    },
    "results": {
      "count": 1,
      "code": "SUCCESS"
    }
  }
}

Was this page helpful? Let us know how we did:

Send feedback about...

Data Loss Prevention API