Ruby is not standard on Mac OS X. EDIT: actually it is, thanks the_french. I would be happy to rewrite that in vanilla shell this evening.
That would be great!
In spite of the fact that Ruby is indeed standard on Mac OS X, a simple shell script would have been clearly lighter. However, for proper JSON escaping of the snippet, you need a full set of replacing rules, which kind of kills the purpose. So I give up.