I tried searching for this, but the results coming up were mostly PHP which had a simple json_decode to make an array etc.
Sadly it seemed (unless I didn't see it) like javascript didn't have this function.
Anywhom, my problem is that I have this relatively small json document that looks like this:
{
"greetings" : [
"hey",
"sup",
"hello",
"hola",
"yo",
"howdy",
"hi",
"hello bot"
]
}
(There's more than that in the entire JSON, but this is really all we need)
I would like to, using javascript, check if any of these are present in my message as shown below:
function isGreeting(message) {
return DICT.greetings.indexOf(message) != -1;
}
var re = '/\b' + DICT.greetings.indexOf(message) + '\b/i';
if (isGreeting(message)) {
console.log(message.search(re));
}
Currently it SOMEHOW works, it detects the greetings if they are not in capitals, but I would like them to be detected no matter how it's written, as shown by my attempt with regex.
How would I go about, that no matter how you greet it (as long as, of course, it is on the list) with any kind of capitals, it would log it? So "Hey" would still log, even if the JSON only says "hey" etc.