Improved sanitization and added test coverage

This PR brings sanitization in line with postgres behavior on special characters and adds test coverage on sanitization. It also tests that an object can be stringified and parsed without change when sanitization is enabled.