I am trying to implement solution in asp.net core 3. I need to make few private properties REDACTED for security purposes while logging into file. As JsonDocument is readonly and I cannot use JsonPath as well, I have shifted to NewtonSoft for this purpose and use JObject.Parse. My concerns are:
How much it will affect my performance?
Will it lead to memory leaks?
Code:
var requestTokens = JObject.Parse(requestBodyText); // parse request/response
foreach (string property in RedactedFields) //for each redacted field in list
{
JToken token = requestTokens.SelectToken(property); // apply jsonpath
if (token != null)
{
// jsonpath found
((Newtonsoft.Json.Linq.JValue)token).Value = "******REDACTED******";
requestTokens.SelectToken(property).Replace(token);
}
}