/// <summary> /// Scrubs the payload. /// </summary> /// <param name="payload">The payload.</param> /// <param name="scrubFields">The scrub fields.</param> /// <returns>System.String.</returns> internal static string ScrubPayload(string payload, IEnumerable <string> scrubFields) { var jObj = JsonScrubber.CreateJsonObject(payload); var dataProperty = JsonScrubber.GetChildPropertyByName(jObj, "data"); JsonScrubber.ScrubJson(dataProperty, scrubFields); var scrubbedPayload = jObj.ToString(); return(scrubbedPayload); }
public void BasicScrubbingTest() { var jsonString = @"{'results' : [ { 'address_components' : 'abc' , 'formatted_address' : 'eedfdfdfdfdfdfdf', 'geometry' : { 'bounds' : { 'northeast' : { 'lat' : 56.88225340, 'lng' : 7.34169940 }, 'southwest' : { 'lat' : 2.4792219750, 'lng' : 6.85382840 }}}}, { 'address_components' : 'abc1' , 'formatted_address' : 'ffdfdfdfdfdfdfdf', 'geometry' : { 'bounds' : { 'northeast' : { 'lat' : 6.88225340, 'lng' : 17.34169940 }, 'southwest' : { 'lat' : 22.4792219750, 'lng' : 16.85382840 }}}} ]}"; string[] scrubFields = new string[] { //"lng", "lat", "southwest", }; string scrubbedJsonString = JsonScrubber.ScrubJson(jsonString, scrubFields); var expectedResult = @"{'results' : [ { 'address_components' : 'abc' , 'formatted_address' : 'eedfdfdfdfdfdfdf', 'geometry' : { 'bounds' : { 'northeast' : { 'lat' : '***', 'lng' : 7.34169940 }, 'southwest' : '***' }}}, { 'address_components' : 'abc1' , 'formatted_address' : 'ffdfdfdfdfdfdfdf', 'geometry' : { 'bounds' : { 'northeast' : { 'lat' : '***', 'lng' : 17.34169940 }, 'southwest' : '***' }}} ]}"; Assert.AreEqual(JObject.Parse(expectedResult).ToString(), JObject.Parse(scrubbedJsonString).ToString()); scrubFields = new string[] { "lng", "lat", "southwest", }; scrubbedJsonString = JsonScrubber.ScrubJson(jsonString, scrubFields); Assert.AreNotEqual(JObject.Parse(expectedResult).ToString(), JObject.Parse(scrubbedJsonString).ToString()); }