Forum Discussion
Haven't done anything with HSL in the past, but given your concerns, I think there's a couple ways you could go about this.
The first would be to use the URI::encode command (since it percent encodes the data like in a URI query string. Info). Problem here is that the data wouldn't be as readable unless you were to decode it later whenever you use it. And this is generally used for URIs instead of data, but it can be useful if it fits your requirements.
My other suggestion would be to use the string map command in TCL to do your own encoding. If you look at the JSON web site, you can see how the format is laid out. At a minimum, you would want to escape double quotes, but you could add more if you were concerned with how another tool may process the JSON code. I don't have an iRule to test on right now but perhaps something like this would work (tested it in tclsh with success):
[string map {\" \\\" } $YourDataToEscape]
Hope this helps. I'm not sure how performant these commands are, though I'd think the string map is better than the other, since it's a built-in TCL command. Maybe somebody else can speak to that aspect of it.