json: better support for escaped strings.
json: cleanup and add more parameters for writing.