use to_json to escape strings, it's close to groovy's escaping