Fix JSON marshalling for arbitrary binary data in strings.

I think this solves things relatively elegantly (compared to the other approaches we discussed).