2

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?

3
  • 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). Commented Sep 9, 2013 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]")... Commented Sep 9, 2013 at 20:40
  • Your json is malformed. Commented Sep 9, 2013 at 21:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.