Awesome!
That would be useful to know earlier ![]()
Try this:
private string RestrictStringTokensToLength(string inJson, int maxLength)
{
JObject obj = JObject.Parse(inJson);
IEnumerable<JValue> stringTokens = obj.Descendants()
.OfType<JValue>()
.Where(v => v.Type == JTokenType.String);
foreach (JValue token in stringTokens)
{
string tokenValue = token.Value.ToString();
if (tokenValue.Length > maxLength)
{
token.Value = tokenValue.Substring(0, maxLength);
}
}
return JsonConvert.SerializeObject(obj, Formatting.None);
}