0

We are trying to query a JSON array with different (sometimes non existent) attributes. Suppose we have the following:

{
  "employees": [
     { "firstName":"John" , "lastName":"Doe" , "favoriteCar":"Ford" }, 
     { "firstName":"Anna" , "lastName":"Smith", "favoritePet":"Cat", "city":"London" }, 
     { "firstName":"Peter" , "lastName":"Jones" , "city":"Ankara" }
     ]
}

As you will notice there are several attributes that do not exist on each "employee" such as "city" or "favoriteCar" and "favoritePet". Given to facts above, can I query this json array with a query string? (any commercial or non-commercial libraries are welcomed)

Sample queries:

  • firstName like 'J%'
  • city = 'Ankara'
  • lastName = 'Doe' AND favoriteCar <> 'Ford'

What I'm trying to do is something like this:

var results = collection.Select("firstName like 'J%'");

meraydin
  • 89
  • 1
  • 1
  • 11
  • I guess you want to query JSON using .net ? – Alexis Côté Sep 08 '16 at 13:42
  • 2
    If you're looking for a JSON "thing" that's analagous to XPath, [I see a few answers here](http://stackoverflow.com/questions/8481380/is-there-a-json-equivalent-of-xquery-xpath). – 15ee8f99-57ff-4f92-890c-b56153 Sep 08 '16 at 13:49
  • Actually, what I'm looking for is to query the collection using a string. Something like this: `var results = collection.Select("firstName like 'J%'");` – meraydin Sep 08 '16 at 18:19
  • see http://www.newtonsoft.com/json/help/html/QueryJsonSelectTokenJsonPath.htm. There's even a tag [tag:jsonpath]. – dbc Sep 08 '16 at 22:18
  • I've checked that before I post this question but I couldn't find anything related to 'like' operator. Do you see any? – meraydin Sep 16 '16 at 08:59

0 Answers0