Using JSONPath with SelectToken to query for JSONPath expressions in your C# application

If you use Newonsoft's Json.NET for the .NET environment, you can use its SelectToken implementation to make JSONPath queries of JSON documents. First, you'll parse the JSON into JObject and then make a query.

Getting ready

You'll need to include the Json.NET assembly in your application. To do this, follow the steps in Chapter 7, Using JSON in a Type-safe Manner, in the Getting ready section of the How to Deserialize an object with Json.NET recipe.

How to do it…

Here's how to extract all titles of all books from the example in the introduction and get the first result:

using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json.Linq; ...

Get JavaScript JSON Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.