Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"any JSON is hyper" claim #13

Open
dret opened this issue Dec 27, 2017 · 14 comments
Open

"any JSON is hyper" claim #13

dret opened this issue Dec 27, 2017 · 14 comments

Comments

@dret
Copy link
Contributor

dret commented Dec 27, 2017

that claim is outright magical and needs to be detailed. in any JSON format i've ever seen, a format puts constraints on how to use JSON. these constraints can be in the form of a schema, or the form of a spec.
i can see how JSON not containing hyper properties can be hyper. that's pretty much the HAL approach to allow plain JSON.
however, as soon as there is data that's mixed in that claims to be hyper, it seems outlandish that every possible JSON data you put in these properties is valid hyper. the spec has a lot of constraints how to use properties. what happens if those constraints are not satisfied? per the claim, that would still need to be valid hyper and thus those constraints have to be removed because every possible value must have a valid hyper interpretation.
as mentioned, the claim as it is made seems magical, and needs a lot of explanation in order to explain to people that as a logical conclusion of that claim, there is no such thing as invalid hyper.

@dret dret changed the title any JSON is hyper claim "any JSON is hyper" claim Dec 27, 2017
@inadarei
Copy link
Owner

Ha! Well, mathematically speaking - you are correct. But as a Physics undergrad, I would argue that the real world doesn't operate in absolutes. There is no "absolute true" and "absolute false". The statement is just "true enough" :)

That said, let's look at the reality and how "true enough" the claim is.

Yes, obviously, Hyper establishes certain additional constraints on JSON, which is why its media type identifier is different from application/json however it is valid to do following things:

  1. You can write JSON object of nearly any shape
  2. If you don't prefix your keys with "h:" prefix or make your attributes be URIs that start with http://hyperjson.io/props/

an arbitrary JSON will never violate anything in Hyper.

Which means that, if we didn't want to provide extensive examples, explanaitons etc. an RFC for Hyper would be just following rules:

  1. Hyper is a JSON of arbitrary shape.
  2. Keys of a Hyper document MAY be URIs, optionally CURIEd. Such attributes indicate extra semantics and processing rules that can be provided by a resource at the other end of the URI, or elsewhere. This is the primary way of extending Hyper.
  3. Applications producing and consuming Hyper acknowledge the implicit existence of a core set of extensions, that is documented at URIs, the root of which is http://hyperjson.io/props/

That's it. The hypothetical RFC doesn't need to say anything else. Because Hyper is built on mixins (plus: core mixin) and not: inheritance. Which is way less than most other hypermedia formats can claim. And therefore the succinct explanation of this fact that you objected to.

Yes, HAL comes close to the same claim (however: there's no other idiomatic place, besides the spec itself which defines what _links and _embedded are and/or what attributes and shapes they can have, so HAL is further than Hyper). If Mike Kelly wants to make the same claim as Hyper does - he's more than welcome to.

If you look at most other hypermedia types, however: Siren, JSONAPI, Collection+JSON, even UBER - they all have constrained shape and don't come nearly as close to the claim as Hyper does.

So in relative, physics-terms, I do think Hyper lives up to its promise.

That said, this is a valid question and we are trying to find a better way to explain in which approximation the claim is true, given how it is not true in absolute terms.

Fair?

@dret
Copy link
Contributor Author

dret commented Dec 30, 2017 via email

@randallsquared
Copy link
Collaborator

“I still think there's potential for trouble. mike tucked all his stuff into one special place. that makes it safe“

@inadarei this is, I think, the same argument I was making when I talked about mixing data and metadata. It’s just a lot simpler to segregate format-specific data into one place. Given the freedom of a HAL Resource to show up anywhere, I’m not sure that HAL is much better in this regard, as long as we only squat on h:* keys, as Kelly did on _* keys.

@inadarei
Copy link
Owner

inadarei commented Dec 30, 2017

It’s just a lot simpler to segregate format-specific data into one place.

@randallsquared since most hypermedia formats that "don't mix data and metadata" do support recursion of some sort (otherwise they would have very limited scope, like in case of Collection+JSON) – metadata is still sprinkled all over the place, so I don't see any fundamental gains in simplicity here. What I do see is - significantly increased verbosity and complexity due to recursion.

I believe the tradeoff here is: "is this simple for whoever parses the document, or whoever designs messages, using this format". And Hyper prioritizes the simplicity of the latter.

Regardless - seggragated data vs. metadata is simply not the design of Hyper, and if such approach is preferred, the choices are already abundant.

@inadarei
Copy link
Owner

what about if i have any other qnames as keys? will those be silently
accepted as "not hyper", or will they trigger a "curie not declared"
warning? or an error?

AFAIK a "qname" is a form of a CURIE, so - I am not sure what you are asking. If you are asking: "what if I have a key with a colon in the name, but it does not start with h: (default CURIE) and is not declared explicitly as a CURIE in h:head.curies" – the answer is: then you just have an attribute whose name contains a colon. It may still be a URI if the part before the colon defines some known URI protocol (e.g. data:) but it is not a CURIE.

There is no magic here:

  1. An attribute MAY be a URI
  2. If an attribute is a URI, it MAY be CURIEd (and will be treated as a CURIE if it is the default h: CURIE or is explicitly declared as a CURIE by documenting in h:head.curies)
  3. If an attribute is a URI, documentation for additional semantics MAY be provided as a resource at the other end of that URI.

In any API, for any attribute in any message - consumer derives semantic meaning of that attribute based on:

  1. Known standards
  2. in-band hints
  3. out-of-band information that the consumer may have access to (documentation).

This is as true for Hyper as it is for anybody else. The difference in Hyper is, it allows a way to provide in-band semantic hints by letting:

  1. Attributes
  2. h:type and
  3. rel

be URIs. And by declaring core h: vocabulary it avoids the need to have hardcoded structure.

That's it

inadarei added a commit that referenced this issue Dec 30, 2017
@inadarei
Copy link
Owner

Spec updated per discussion here: http://hyperjson.io/spec.html#design-choices

I hope it addresses your concerns much better than the original did.

@dret
Copy link
Contributor Author

dret commented Dec 30, 2017 via email

@dret
Copy link
Contributor Author

dret commented Dec 30, 2017 via email

@inadarei
Copy link
Owner

JSON has no attributes. it has objects with members, which have
names/keys, and values. i am really not clear about what you mean by "an
attribute is a URI".

Everywhere I say "attribute" I mean a key of a JSON object.

@dret
Copy link
Contributor Author

dret commented Dec 30, 2017 via email

@inadarei
Copy link
Owner

inadarei commented Dec 30, 2017

:) wel, yes. Based on that ABNF, it is called "string name of a member of a JSON object", to be precise. But that is 5 words instead of "an attribute" so I am a bit hesitant doing a "find replace" and using that many words :)

@dret
Copy link
Contributor Author

dret commented Dec 30, 2017 via email

@inadarei
Copy link
Owner

inadarei commented Dec 30, 2017

Understood. But calling 'attribute' the name of a data member of an object, in general, is a common thing (as you said - not necessarily in JSON RFC). Edited spec to define the terminology early on, and thus remove ambiguity:

Keys of JSON objects in a Hyper document (referred to as 'attributes' in the rest of this spec, for brevity) MAY be URIs. In Hyper, attributes that are valid URIs indicate extra semantics and processing rules

http://hyperjson.io/spec.html#design-choices

@dret
Copy link
Contributor Author

dret commented Feb 14, 2018

so, did we make any progress on the fundamentals of this? the question still is open how the processing model treat member names/values when they syntactically match hyper's rules, but semantically don't.
i think what it boils down to is: can you write a hyper processor that takes any JSON, and then flags each individual value in it in terms of how it has to be interpreted? this would have to work for any possible hyper extension, so that it is always well defined what parts of a JSON document are supposed to have hyper semantics, or at which point a hyper processor would raise errors and complain about hyper constraints being violated.
it seems much of the nitty gritty of this is still open. for example, looking at a value, then looking at colons, and then classifying this as a CURIE or a URI based on the string in front of the colon seems odd. processors will never have complete knowledge of all URI schemes, and this is not a closed list to begin with. that's why the actual CURIE spec has a special syntax to distinguish URIs and CURIEs when the context doesn't allow to distinguish between those two: https://www.w3.org/TR/2010/NOTE-curie-20101216/#sec_2.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants