News for hackers. Stuff that matters.
Re:Transit – A format for conveying values between different... by BinaryIdiot on Tuesday July 22, 2014 @02:17PM (#8070642)
I like the idea of schemas but only when they're built into the message (which is probably not a good way of conveying my meaning).

Essentially JSON gives you numbers, strings and nulls so when accepted on the other side it obviously knows what's a number, what's a string, etc.

Honestly if JSON could be expanded to essentially be the same but add additional types along with bolting on new types (extensible) then I think it would be perfect for the job.

At least in my opinion.

Re:Transit – A format for conveying values between different... by haberman on Tuesday July 22, 2014 @03:09PM (#8070982)
Schemas built into the message certainly have the benefit of being self-describing. But they also have downsides:

- encoding the schema along with the message makes encodings like this less efficient.

- without an ahead-of-time schema, you don't have any canonical list for all the fields that can exist and their types. Instead this gets specified in ad-hoc ways in documentation. For example, like this: https://developers.facebook.com/docs/graph-api/reference/v2....

That URL describes a schema for groups. The schema exists, it's just not machine-readable! That means you can't use it for IDE auto-completion, you can't reflect over it programmatically, and you can't use it to make encoding/decoding more CPU/memory efficient. It's so close to being useful for these purposes, why not just take that final step and put it in a machine-readable format?

Re:Transit – A format for conveying values between different... by alexatkeplar on Tuesday July 22, 2014 @03:16PM (#8071032)
It's really frustrating how in 2014 almost everybody is still writing API definitions which are only human-readable. Two worthy exceptions:

- https://github.com/balanced/balanced-api - https://helloreverb.com/developers/swagger

You can have self-describing messages without having to embed the schema in the instance. Instead you embed a reference to the schema in the message. We came up with an approach to this called self-describing JSONs: http://snowplowanalytics.com/blog/2014/05/15/introducing-sel... The Avro community do something similar.

Re:Transit – A format for conveying values between different... by judk on Tuesday July 22, 2014 @03:31PM (#8071108)
> Instead you embed a reference to the schema in the message

AKA XML DTD

Re:Transit – A format for conveying values between different... by stdbrouw on Tuesday July 22, 2014 @02:28PM (#8070712)
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.
Re:Transit – A format for conveying values between different... by ochoa on Tuesday July 22, 2014 @02:37PM (#8070778)
Dumb question: why doesn't the value being a number tell us it's suppose to be a number?
Re:Transit – A format for conveying values between different... by michaelmior on Tuesday July 22, 2014 @02:47PM (#8070841)
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.
Re:Transit – A format for conveying values between different... by kalleboo on Wednesday July 23, 2014 @12:47AM (#8072950)
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?
Re:Transit – A format for conveying values between different... by elros on Wednesday July 23, 2014 @04:57AM (#8073419)
Definitely as a string. Numbers aren't things that have digits. Numbers are things you do math with.
Re:Transit – A format for conveying values between different... by kalleboo on Wednesday July 23, 2014 @08:39AM (#8074008)
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?