Encode key/value pairs for database storage.