Can I LINQ a JSON?

No need for Linq, just use dynamic (using Json.Net)

dynamic obj = JObject.Parse(json);
Console.WriteLine((string)obj.picture.data.url);

Linq version would not be much readable

JObject jObj = JObject.Parse(json);
var url = (string)jObj.Descendants()
                    .OfType<JProperty>()
                    .Where(p => p.Name == "url")
                    .First()
                    .Value;

Documentation: LINQ to JSON

Leave a Comment