Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

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 has been asked before and already has an answer. If those answers do not fully address your question, please ask a new 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.