Re:Log Everything as JSON. Make Your Life Easier.
by jerf on Thursday April 26, 2012 @10:12PM
(#3897162)
"Don't you have to worry about escaping a whole bunch of characters just in case something gets the wrong idea about what you have in a field?"
Either you're using a length-delimited format, which is pretty hostile for humans to read, or you're using a string that will require something to be escaped.
The only third option is bugs, like a newline that gets out into your logs and oops, new log line.
"I saw a page not too long ago which listed about a dozen characters which should be substituted in some manner when used in JSON."
It is very likely what you saw was the list of Unicode characters that are accepted by the JSON format but rejected by browsers and/or HTML in the context of a Javascript embedded in an HTML page. In this case, it's the browsers and/or JS-in-HTML with the issue, not JSON. And I don't mean that as a who-to-blame sort of issue, I mean, if you're producing JSON and consuming JSON and it doesn't pass through HTML it's a non-issue, and any string that passes through JS-in-HTML will have the same problem even if it isn't "JSON", so it really hasn't got anything to do with JSON if I am correct about what you're referring to.
Either you're using a length-delimited format, which is pretty hostile for humans to read, or you're using a string that will require something to be escaped.
The only third option is bugs, like a newline that gets out into your logs and oops, new log line.
"I saw a page not too long ago which listed about a dozen characters which should be substituted in some manner when used in JSON."
It is very likely what you saw was the list of Unicode characters that are accepted by the JSON format but rejected by browsers and/or HTML in the context of a Javascript embedded in an HTML page. In this case, it's the browsers and/or JS-in-HTML with the issue, not JSON. And I don't mean that as a who-to-blame sort of issue, I mean, if you're producing JSON and consuming JSON and it doesn't pass through HTML it's a non-issue, and any string that passes through JS-in-HTML will have the same problem even if it isn't "JSON", so it really hasn't got anything to do with JSON if I am correct about what you're referring to.