Is it possible to determine if a JSON object contains a specified "fieldname".
For example:
If I have a JSON Object such as:
{"event":
[
{"query":
{"id":
[
{"timestamp_usec":"1316596939223064"}
],
"query_text":"sometext"
}
},
{"query":
{"id":
[
{"timestamp_usec":"1316318681908642","type":"sometype","abc":"someabc"},
{"timestamp_usec":"1316318679366796"}
],
"query_text":"someothertext"
}
},
//...More...//
]
}
What can I use as my conditional within an if statement
to determine if a particular "id object" contains an "abc"?
More Simply:
FOR ALL jsonpath id's
IF jsonpath.id **CONTAINS** "abc"
THEN do something
ELSE do something different
END LOOP
I'm looking for the jQuery function to achieve this (if there is one!).
My Code:
$.getJSON("test.json", function(data) {
var search = data.event
$.each(data.event, function(i, item) {
var searchMeta = data.event[i].query.id;
$.each(searchMeta[i], function(i, deeper){
if (searchMeta[i]. == "abc"){
//do something
} else {
//do something different
}
})
})
});
I know in the above example I could essentially achieve what I want by looping on the number of id objects, eg If num < 1. But I am not sure how uniform my data is throughout more than one .json file.