Properly encode JSON strings