I'm trying to search JSON specifically by keyword. I've successfully searched by an ID, which in the code below, is "tags". Though, what I want to do is, search within the ID of "tags" but by the keyword of "depreciated". Only the bracketed in JSON that say "depreciated" will be selected. Then the title and uri will be pulled from that and written to the document, like I have in my code.
How might I go about doing a keyword search with my current code? If my logic is hard to understand, please let me know in the comments. Thanks in advance :)
Note: This is exactly the JSON format in which the data will be used.
Here's my code:
<script type='text/javascript'>
window.onload=function(){
var data = {
"Feed": [
{
"categories":[
"Depreciated",
"Test"
],
"content":"",
"tags":[
"Depreciated",
"Test"
],
"title":"Visual Design",
"uri":"google.com"
},
{
"categories":[
"Depreciated"
],
"content":"",
"tags":[
"Depreciated"
],
"title":"Typography",
"uri":"google.com"
}
]
},
res = JSON.search( data, '//*[tags]' );
for (var i=0, str=''; i<res.length; i++) {
str += '<a href="' + res[i].uri + '">Link</a>' + res[i].title + '<br/>';
}
document.getElementById('output').innerHTML = str;
}
</script>