Select object based on condition inside a nested array

n1ql unnest example
accessing nested objects javascript
javascript search nested array of objects
jsonata filter
iterate nested array of objects javascript
javascript find value in nested object
nested arrays javascript
javascript access nested array

I have a Jarray of response and inside Jarray there is an array of Clients and based on the condition I need to select the object in Array Json is

JArray response = JArray.Parse(@"[
                    'ProviderTransactionID': '4c4c5b43-0dd6-490c-9a59-062e25c04019',
                     'IsSuccess': 'False',
                     'ErrorMessages': 'Some error',
                      'ClientInfo': [
                         'InternalID': '98367',
                         'UniqueID': '',
                         'ErrorMessages': 'ERROR:'
                         'InternalID': '98368',
                         'UniqueID': '',
                         'ErrorMessages': 'ERROR:'

For example, I need to select the ClientInfo Object where InternalID=98367


response.SelectToken("ClientInfo") returning null

response.SelectToken("ClientInfo") as JArray returning null

response.SelectTokens("ClientInfo") not returning any result

response.Children().Where(lst=>lst.SelectToken("ClientInfo").HasValues) is throwing Arg_PlatformNotSupported exception

response.SelectTokens("ClientInfo").Where(lst=>lst.Value<int>()==98367).FirstOrDefault() is returning null

can anyone please help me with how to get all ClientInfo object matching ID in an array of responses?

Based on the documentation ( a possible solution can be:


Database and Expert Systems Applications: 14th International , which are defined on the base cell type are also defined on multidimensional arrays. All multidimensional data objects for which the condition tree evaluates true are The simplified structure of such a RasQL query is SELECT <array operation> In the whereclause a multidimensional condition is evaluated on the  The two query mechanism work in different ways, as suggested in the docs at the section Subdocuments:. When the field holds an embedded document (i.e, subdocument), you can either specify the entire subdocument as the value of a field, or “reach into” the subdocument using dot notation, to specify values for individual fields in the subdocument:

You can query JSON with LINQ as below:

var Result = (from p in response
                           select new
                               Errors = (from z in p["ClientInfo"]
                                         where (string)z["InternalID"] == "98368"
                                         select new
                                             InternalID = (string)z["InternalID"],
                                             UniqueID = (string)z["UniqueID"],
                                             ErrorMessages = (string)z["ErrorMessages"],


we can use anonymous type .net will create class intrenally. if you want to use Parent data element also say ProviderTransactionID below code will work for that also

        var Result = (from p in response
                           select  (from z in p["ClientInfo"]
                                         where (int)z["InternalID"] == 98368
                                         select new
                                             ProviderTransactionID = (string)p["ProviderTransactionID"],
                                             InternalID = (int)z["InternalID"],
                                             UniqueID = (string)z["UniqueID"],
                                             ErrorMessages = (string)z["ErrorMessages"],


Base SAS 9.4 Procedures Guide, Fifth Edition, The selected observations are exported as nested array containers and consist of The WRITE VALUE statement nests the user-defined string Results in the causes the selected observations to be exported as nested object containers and​  The Select-Object cmdlet selects specified properties of an object or set of objects. It can also select unique objects, a specified number of objects, or objects in a specified position in an array. To select objects from a collection, use the First, Last, Unique, Skip, and Index parameters. To select object properties, use the Property parameter. When you select properties, Select-Object

If you don't want to use a class then you need something like this:

JArray jArray = JArray.Parse("[\r\n                  {\r\n                    'ProviderTransactionID': '4c4c5b43-0dd6-490c-9a59-062e25c04019',\r\n                     'IsSuccess': 'False',\r\n                     'ErrorMessages': 'Some error',\r\n                      'ClientInfo': [\r\n                       {\r\n                         'InternalID': '98367',\r\n                         'UniqueID': '',\r\n                         'ErrorMessages': 'ERROR:'\r\n                       },\r\n                       {\r\n                         'InternalID': '98368',\r\n                         'UniqueID': '',\r\n                         'ErrorMessages': 'ERROR:'\r\n                       }\r\n                     ]\r\n                   }\r\n            ]");

const string internalId = "98367";

foreach (JToken obj in jArray)
    IEnumerable<JToken> clientInfoObjects = obj.SelectToken("ClientInfo").Where(clientInfoJToken => clientInfoJToken["InternalID"].Value<string>() == internalId);

So because you are parsing into a JArray you need to iterate through the objects (although only one in your case).

Then you are at your object level so you can use .SelectToken("ClientInfo") which gives you a JToken (JArray) enabling you to use .Where() to filter the objects to your requirements.

The result is an IEnumerable<JToken> which will be the ClientInfo objects with the id you specify.

UNNEST clause, +. The UNNEST clause creates an input object by flattening an array in the parent document. If a document or object contains a nested array, UNNEST conceptually Syntax. unnest-clause ::= from-term [ unnest-type ] ( UNNEST | FLATTEN ) expr SELECT sched FROM `travel-sample` UNNEST schedule sched WHERE  JavaScript : find an object in array based on object's property (and learn about the "find" function) Published on March 20, 2017 March 20, 2017 • 314 Likes • 48 Comments Report this post

Pro Couchbase Development: A NoSQL Platform for the Enterprise, N1Ql's use cases include complex queries embedded in applications, and analytics are based on a flexible schema JSON model with nested objects and arrays. a SELECT Query • Filtering with WHERE Clause • JSON with Nested Objects Including and Excluding Null and Missing fields • Using Multiple Conditions  Nested subqueries. A subquery can be nested inside other subqueries. SQL has an ability to nest queries within one another. A subquery is a SELECT statement that is nested within another SELECT statement and which return intermediate results. SQL executes innermost subquery first, then next level. See the following examples :

Query an Array of Embedded Documents, MongoDB Manual - how to query an array of documents, how to query an array of nested documents, how to query an array of embedded documents. Query and Update documents nested multiple levels in an array The $ positional operator is used to project elements in an array based on a condition. The $ operator can be used to project fields in documents nested deeply in an array. MongoDB can only project fields nested at only a single level when the $ operator is used.

Traversing Nested Objects, Well, like the lists in the index in the example above, the values in an object can also be Given the above nested array, how would we get the number 6 ? In fact, writing functions that test some condition (a "criteria function") is so common,​  Nested arrays. An array inside an array is called a nested array. I don’t use these much in PowerShell but I have used them more in other languages. Consider using an array of arrays when your data fits in a grid like pattern. Here are two ways we can create a 2 dimensional array.