O'Reilly logo

JavaScript JSON Cookbook by Ray Rischpater

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required