Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I wish to query json result data to be used in Razor view and would like to know how to search by a specific id and capture data for a specific node:

Here is an example(just a part) of my json:

{
   "maxPages":1,
   "data":[
      {
         "id":"123",
         "perfomanceData":[
            {
               "platform":{
                  "name":"Test0",
                  "id":0
               }, 
         ],
     {
         "id":"124",
         "perfomanceData":[
            {
               "platform":{
                  "name":"Test1",
                  "id":0
               }, 
         ],
     {
         "id":"125",
         "perfomanceData":[
            {
               "platform":{
                  "name":"Test2",
                  "id":0
               }, 
         ],

I wish to search by an ID example 125 and retrieve just this section

perfomanceData":[
                {
                   "platform":{
                      "name":"Test2",
                      "id":0
                   }, 
             ]

How can I use JavaScript to do the above?

share|improve this question

marked as duplicate by bfavaretto, Felix Kling, carlosfigueira, Bergi, Andrew Whitaker Sep 9 '13 at 21:46

This question was marked as an exact duplicate of an existing question.

2  
Please note that the problem has nothing to do with JSON but rather with how to process JS arrays and objects. How you got the data is irrelevant (unless you really want to process raw JSON data in JS, i.e. apply string processing, which is probably more complicated than parsing the JSON). – Felix Kling Sep 9 '13 at 20:10
    
look into taffyDB, you can turn your json into taffy with one line, then use taffy's query features. if you need something simpler, danml.com/js/oquery.js works like oQuery( obj, "[id=125]")... – dandavis Sep 9 '13 at 20:40
    
Your json is malformed. – acdcjunior Sep 9 '13 at 21:36

Browse other questions tagged or ask your own question.