using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public static void Main()
"@xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/",
"@xmlns:awsse": "http://xml.amadeus.com/2010/06/Session_v3",
"@xmlns:awsl": "http://wsdl.amadeus.com/2010/06/ws/Link_v1",
"@xmlns:wsa": "http://www.w3.org/2005/08/addressing",
"wsa:To": "http://www.w3.org/2005/08/addressing/anonymous",
"wsa:Address": "https://nodeA3.test.webservices.amadeus.com/1ASIWTKRMHU"
"wsa:Action": "http://webservices.amadeus.com/QDQLRQ_11_1_1A",
"wsa:MessageID": "urn:uuid:117e8bbe-d009-7234-7573-9fcf054b7ef8",
"@RelationshipType": "http://www.w3.org/2005/08/addressing/reply",
"#text": "Smj1zmw2GhqFKlNtw5uhXg=="
"awsl:TransactionFlowLink": {
"awsl:UniqueID": "2YeVW3Nh2QjqstAp6LhUgw=="
"awsl:ServerID": "urn:uuid:2628c914-e19a-5b4a-b402-b6600554a6cf"
"@TransactionStatusCode": "End",
"awsse:SessionId": "00HEQ5U4CN",
"awsse:SequenceNumber": "1",
"awsse:SecurityToken": "37BJQUY4G7GRRY3GBN9MV80OL"
"@xmlns": "http://xml.amadeus.com/QDQLRR_11_1_1A",
"inHouseIdentification1": "KULMH08AA"
"identificationType": "C",
"controlNumber": "TW85V2"
"departureDate": "23AUG20"
"flightIdentification": {
"inHouseIdentification1": "KULMH0676",
"inHouseIdentification2": "SM"
JToken token = JToken.Parse(json);
string[] jsonPaths = ExampleConfigSettings.GetJsonPathsToObscure();
JsonHelper.ObscureMatchingValues(token, jsonPaths);
ExampleLogger.Log(token.ToString(Formatting.None));
public static class JsonHelper
public static void ObscureMatchingValues(JToken token, IEnumerable<string> jsonPaths)
foreach (string path in jsonPaths)
foreach (JToken match in token.SelectTokens(path))
match.Replace(new JValue(Obscure(match.ToString())));
public static string Obscure(string s)
if (string.IsNullOrEmpty(s)) return s;
int leftLen = len > 4 ? 1 : 0;
int rightLen = len > 6 ? Math.Min((len - 6) / 2, 4) : 0;
return s.Substring(0, leftLen) +
new string('*', len - leftLen - rightLen) +
s.Substring(len - rightLen);
public static class ExampleConfigSettings
public static string[] GetJsonPathsToObscure()
return new string[] { "$..Password", "$..credit_card.number" };
public static class ExampleLogger
public static void Log(string s)
Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff") + " - " + s);