Click or drag to resize
Json.NET

JSON Path strict equals operator

 

This sample loads JSON and then queries values from it using SelectToken(String) with a strict equals JSON Path.

Sample
Usage
JArray items = JArray.Parse(@"[
  {
    'Name': 'Valid JSON',
    'Valid': true
  },
  {
    'Name': 'Invalid JSON',
    'Valid': 'true'
  }
]");

// Use === operator. Compared types must be the same to be valid
List<JToken> strictResults = items.SelectTokens(@"$.[?(@.Valid === true)]").ToList();

foreach (JToken item in strictResults)
{
    Console.WriteLine((string)item["Name"]);
}
// Valid JSON