# JSON Parsing Question

**URL:** <https://boards.straightdope.com/t/json-parsing-question/727778>\
**Category:** Factual Questions\
**Created:** [August 13, 2015, 9:34pm UTC](https://boards.straightdope.com/t/json-parsing-question/727778 "2015-08-13T21:34:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fiddle\_Peghead](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/fiddle_peghead/32/3506_2.png) [@Fiddle\_Peghead](https://boards.straightdope.com/u/Fiddle_Peghead)\
**Post date:** [August 13, 2015, 9:34pm UTC](https://boards.straightdope.com/t/json-parsing-question/727778/1 "2015-08-13T21:34:04Z")

</div>

On a tech site, I posed this question:

With the following json

{  
“Count”:0,  
“Message”:{  
“AppId”:0  
},  
“Data”:"[{“application\_name”: “Grand Central”,“feature\_name”: “1 Click Fix”,“access\_type\_id”: 2,“member\_name”: “GC\_Remote\_Support\_Security”},{“application\_name”: “Grand Central”,“feature\_name”: “Account Details”,“access\_type\_id”: 2,“member\_name”: “GC\_Remote\_Support\_Security”},{“application\_name”: “Grand Central”,“feature\_name”: “Account Summary”,“access\_type\_id”: 2,“member\_name”: “GC\_Remote\_Support\_Security”}]"  
}

How do I go through the Data array, in the most succinct coding manner possible, to see if any feature\_name matches a given string?

This was an answer:

var testString = “Account Summary”;  
var found = JToken.Parse(JObject.Parse(jsonString)[“Data”].ToString()).SelectTokens("…feature\_name").Any(t =\> (string)t == testString);  
Debug.Assert(found == true); // No assert.  
So far, so good.

Now I want to get the actual item that matches the feature name. How do I do it? I can’t figure it out and really need to get this to work for my job.

I’d like to do it with linq like the first one, but any method is fine.

---

<div class="post-metadata">

**Author:** ![arseNal](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@arseNal](https://boards.straightdope.com/u/arseNal)\
**Post date:** [August 13, 2015, 11:37pm UTC](https://boards.straightdope.com/t/json-parsing-question/727778/2 "2015-08-13T23:37:39Z")

</div>

If I understand correctly:

(this is just plain javascript, i don’t know that fancy linq stuff. also, i use the evil eval() function! which must be what your JObject.parse() does)

```auto

var json= {
"Count":10,
"Message":{
"AppId":0
},
"Data":"[{\"application_name\": \"Grand Central\",\"feature_name\": \"1 Click Fix\",\"access_type_id\": 2,\"member_name\": \"GC_Remote_Support_Security\"},{\"application_name\": \"Grand Central\",\"feature_name\": \"Account Details\",\"access_type_id\": 2,\"member_name\": \"GC_Remote_Support_Security\"},{\"application_name\": \"Grand Central\",\"feature_name\": \"Account Summary\",\"access_type_id\": 2,\"member_name\": \"GC_Remote_Support_Security\"}]"
};
var testString = "Account Summary";
var dataComponent = eval(json.Data);
for (var data in dataComponent) {
	featureName = dataComponent[data]['feature_name'];
	if (featureName == testString) {
		alert(JSON.stringify(dataComponent[data]));
	}
}

```

---

<div class="post-metadata">

**Author:** ![Fiddle\_Peghead](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/fiddle_peghead/32/3506_2.png) [@Fiddle\_Peghead](https://boards.straightdope.com/u/Fiddle_Peghead)\
**Post date:** [August 14, 2015, 3:01am UTC](https://boards.straightdope.com/t/json-parsing-question/727778/3 "2015-08-14T03:01:31Z")

</div>

Thanks. I forgot to mention this is C#, and JToken/JObject are Newtonsoft. I’d really like to do this with LINQ though. I feel it’s just beyond my grasp. And that I need a similar function to “Any” being used. Anyone?

---

<div class="post-metadata">

**Author:** ![Punoqllads](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@Punoqllads](https://boards.straightdope.com/u/Punoqllads)\
**Post date:** [August 14, 2015, 6:06am UTC](https://boards.straightdope.com/t/json-parsing-question/727778/4 "2015-08-14T06:06:24Z")

</div>

Off the top of my head…

Instead of using JToken.Parse/SelectToken to pull out a given field from your object you’ll just use the list referenced by JObject.Parse(jsonString)[“Data”]. Instead of using List.Any() you’ll want to use List.Find(). Assuming the list is a list of Map\<String, String\>, your predicate test will try to get the value corresponding to key “feature\_name” and return true only if it exists and the value is “Account Summary”.
