Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A Modest Proposal that will never be implemented: add an interface to String, Boolean, Integer, Long, Float and Double. Because all these types already implement "toString" (and I believe their toString representations are compatible with JSON), it can be a pure marker interface.


> I believe their toString representations are compatible with JSON

Not quite. String is the big problem, since it needs to be wrapped in quotes, and special characters need to be escaped. But Float and Double are also problematic because Infinity and NaN aren't representable in json.

However, the new interface could have a "toJsonString" or maybe even a toJson method that returns a JsonValue


JSON String requires escaping of control characters. .toString() on a String is (hopefully) the identity.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: