With json.net, is there a shortish way to manipulate all string fields? -


given arbitrary newtonsoft.json.linq.jobject, if want apply function string values appear in (wherever may be) - whether basic value of property, or in array in json, best way this?

one simple way use jcontainer.descendantsandself() find descendants of root jobject string values, replace value remapped string using jtoken.replace():

public static class jsonextensions {     public static jtoken mapstringvalues(this jcontainer root, func<string, string> func)     {         foreach (var value in root.descendantsandself().oftype<jvalue>().where(v => v.type == jtokentype.string).tolist())             value.replace((jvalue)func((string)value.value));         return root;     } } 

then use like:

jobj.mapstringvalues(s => "remapped " + s); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -