This is what I do, I don't know if it helps. If it's really stupid, I keep asking them what the joke means. The more they explain, the more obvious it makes the inappropriateness of whatever they said. Like Socrates

. If it's aimed at someone, I just don't laugh, I don't like picking on people. But the first one (to keep asking them what different things in a stupid joke mean) works best, because it soon becomes glaringly obvious that it's not actually funny. It's worked well for me.