Improve selection serialization to JSON and fix issue in deserialization.