Add escaping of U+2028 and U+2029 inside the JSON encoder

U+2028 and U+2029 are allowed inside strings in JSON (as are all literal
Unicode characters) but JavaScript defines them as newline separators.
Because no literal newlines are allowed in a string, this causes a
ParseError in the browser.  We work around this issue by replacing them
with the escaped version.  The resulting JSON is still valid and can be
parsed in the browser.

This change was based on [this pull request][1] in mainline Rails.

[1] https://github.com/rails/rails/pull/10534