Function escaping string to JSON-safe form