using Newtonsoft.Json.Linq;
public static void Main()
Console.Write(@"{ ""Test1"": "+ "\n ");
Console.WriteLine(ModifyJSON(googleSearchText, "$.responseData.cursor.pages[?(@.label>=3)]", "{ 'start': '00', 'label': -1 }", Formatting.Indented));
Console.Write(@"},{ ""Test2"": "+ "\n ");
Console.WriteLine(ModifyJSON(googleSearchText, "$.responseData.results[*]", "{ 'url': '~~ url masked ~~', 'visits': 6, 'visible': true, 'pages': null }", Formatting.Indented));
public static string ModifyJSON(string jsource, string jpath, string jstr, Formatting jf = Formatting.None)
JObject jobj = JObject.Parse(jsource);
JObject update = JObject.Parse(jstr);
foreach (var token in jobj.SelectTokens(jpath))
foreach (var x in update)
token.SelectToken(name).Replace(value);
return JsonConvert.SerializeObject(jobj, jf);
static string googleSearchText = @"{
'GsearchResultClass': 'GwebSearch',
'unescapedUrl': 'http://en.wikipedia.org/wiki/Paris_Hilton',
'url': 'http://en.wikipedia.org/wiki/Paris_Hilton',
'visibleUrl': 'en.wikipedia.org',
'cacheUrl': 'http://www.google.com/search?q=cache:TwrPfhd22hYJ:en.wikipedia.org',
'title': '<b>Paris Hilton</b> - Wikipedia, the free encyclopedia',
'titleNoFormatting': 'Paris Hilton - Wikipedia, the free encyclopedia',
'visits': 0, 'visible': false,
'content': '[1] In 2006, she released her debut album...'
'GsearchResultClass': 'GwebSearch',
'unescapedUrl': 'http://www.imdb.com/name/nm0385296/',
'url': 'http://www.imdb.com/name/nm0385296/',
'visibleUrl': 'www.imdb.com',
'cacheUrl': 'http://www.google.com/search?q=cache:1i34KkqnsooJ:www.imdb.com',
'title': '<b>Paris Hilton</b>',
'titleNoFormatting': 'Paris Hilton',
'visits': 0, 'visible': false,
'content': 'Self: Zoolander. Socialite <b>Paris Hilton</b>...'
'estimatedResultCount': '59600000',
'moreResultsUrl': 'http://www.google.com/search?oe=utf8&ie=utf8...'