Fix JSON (de)serialization logic