In one component of my current project, I need to grab the value of a property by name from a given JSON string. This JSON string is dynamic and I don’t know which strongly typed class to deserialise it to. Below is the function I ended up with to solve this problem.
public string ExtractJsonNodeValue(string rawJson, string nodeName)
{
var jObject = (JObject)JsonConvert.DeserializeObject(rawJson);
return jObject.SelectToken($"..{nodeName}")?.ToString() ?? string.Empty;
}