0

I have the following JSON:

{
   "head":{
      "vars":[
         "uri",
         "label"
      ]
   },
   "results":{
      "bindings":[
         {
            "uri":{
               "type":"uri",
               "value":"http://tematres.befdata.biow.uni-leipzig.de/vocab/?tema=751"
            },
            "label":{
               "type":"literal",
               "xml:lang":"en",
               "value":"15n"
            }
         },
         {
            "uri":{
               "type":"uri",
               "value":"http://tematres.befdata.biow.uni-leipzig.de/vocab/?tema=916"
            },
            "label":{
               "type":"literal",
               "xml:lang":"en",
               "value":"16s analysis"
            }
         },
         {
            "uri":{
               "type":"uri",
               "value":"http://tematres.befdata.biow.uni-leipzig.de/vocab/?tema=622"
            },
            "label":{
               "type":"literal",
               "xml:lang":"en",
               "value":"16s rrna"
            }
         },
         {
            "uri":{
               "type":"uri",
               "value":"http://tematres.befdata.biow.uni-leipzig.de/vocab/?tema=917"
            },
            "label":{
               "type":"literal",
               "xml:lang":"en",
               "value":"16s rrna gene analysis"
            }
         },
         {
            "uri":{
               "type":"uri",
               "value":"http://tematres.befdata.biow.uni-leipzig.de/vocab/?tema=618"
            },
            "label":{
               "type":"literal",
               "xml:lang":"en",
               "value":"18s rdna"
            }
         }
      ]
   }
}

Is there any way to get only the uri value and the corresponding label value in a map or so, to fill a table with these values later.

Benny Bottema
  • 11,111
  • 10
  • 71
  • 96
auicsc
  • 297
  • 1
  • 3
  • 14
  • Your question title is asking how to parse some JSON. Your question body gives an example of JSON, but then asks about how to extract specific data from the resulting JavaScript object. What problem are you actually having? – Quentin Sep 09 '14 at 10:17
  • @Quentin, I modified the title. Thanks for the remark – auicsc Sep 09 '14 at 10:18

2 Answers2

1

Use map to extract the information you need into an array. Here I've added the label and URIs to objects that you can loop over when you need to:

var results = json.results.bindings.map(function (el) {
    return { uri: el.uri.value, label: el.label.value };
});

DEMO

Andy
  • 61,948
  • 13
  • 68
  • 95
0

you can simply iterate over like

json = "your json";

yourMap = [];
for(var i = 0; i < json.results.bindings.length; i++){ 

    yourMap[i]= [json.results.bindings[i].uri.value, json.results.bindings[i].label.value ];


}
console.log(yourMap);

here you have a working fiddle

http://jsfiddle.net/xyek6wda/4/

check the console output, it outputs an array containing the uri and label pairs

john Smith
  • 17,409
  • 11
  • 76
  • 117