Skip to content

Instantly share code, notes, and snippets.

@winnicki
Last active September 15, 2017 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save winnicki/b62cfe1623cf66d4e1bd8d28b4c35e51 to your computer and use it in GitHub Desktop.
Save winnicki/b62cfe1623cf66d4e1bd8d28b4c35e51 to your computer and use it in GitHub Desktop.
A Simple LINQ to JSON Query
public async Task<JObject> GetLocationJObject(int locationId)
{
return await Task.Run(() =>
{
var companyJObject = JObject.Parse(RawJson.Company); // parsing to JObject is fast even for large objects
var locationJObject = companyJObject[nameof(Company.Locations)]?
.FirstOrDefault(x => (int)x[nameof(Location.Id)] == locationId) as JObject;
return locationJObject;
})
.ConfigureAwait(false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment