mm1975 mm1975 - 1 year ago 105
Javascript Question

Search in Json for string

I would like to look for certain values in my Json.

Search for the type "patientSize" and find the value of the "coveredText".

Actually, the console throws out found:[]

Since I have to perform some searches, I am looking for a fast and high-performance possibility. Thank you for your tips.

Example JSON

"annoDs": [
"begin": 512,
"end": 518,
"type": "patientSize",
"coveredText": "183 cm",
"additionalParameters": {
"unit": "Zentimeter",
"value": "183"




var data = JSON.parse(retrievedAnnotation);
setTimeout(function() {

function getAge(code) {
return data.annoDs.filter(
return data.code == code;

var found = getAge('patientSize');
console.log("found:", found);
}, 50);

Answer Source

The function getAge must be like this

function getAge(code) {
  return data.annoDs.filter(function(data) {
    return data.type === code;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download