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

You're talking about typing, not really about schemas. With JSON, you can know whether a value is a number as opposed to a string, but you can't know whether it's supposed to be a number.


Dumb question: why doesn't the value being a number tell us it's suppose to be a number?


Assuming the service is operating correctly, I think the more accurate statement is that it doesn't tell you the value will always be a number. That is, perhaps a field has multiple valid types. Maybe that field won't exist all the time or similar data may be available in a different struture. Without a schema, these questions can't really be answered.


Example: Postal codes. Say you're transferring an address in JSON and you have a postal code field. In the UK, postal codes are strings (e.g. "BS42BG"), easy enough. Now, someone enters a US postal code (90505). Should we transfer it as a number, or a string?


Definitely as a string. Numbers aren't things that have digits. Numbers are things you do math with.


OK, that's logical. So where do we specify this without a schema? What happens if a client sends a number instead of a string to the server? Should it accept it and convert it, or return an error?




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

Search: