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

Summary of JSON serialization approach #80

Open
hvdsomp opened this Issue Aug 30, 2017 · 10 comments

Comments

Projects
None yet
4 participants
@hvdsomp
Copy link
Collaborator

hvdsomp commented Aug 30, 2017

This is not really an "issue" per se, but I felt it would be good to have an overview of what I think is the current consensus in one spot. So, here goes.

Overall serialization approach:

  • for non-repeatable parameters, parameter values are conveyed as strings
  • repeatability of parameters is handled by means of an array of strings whereby each string represents a parameter value
  • parameters with unknown repeatability are de-facto handled as repeatable
  • parameters of the token* variant are handled by means of an array of a parameter value and an optional (?) language tag associated with the parameter value

CASE 1 - Relation Type

=> applies to: rel, rev

APPROACH — — array of relation types to convey one or more typed link(s) that share a context and target URI

PATTERN — — “rel” : [“relname”]
PATTERN — — “rel” : [“relname” , “relname”]

  • rel MUST be represented as an array of relation types
  • when starting from the native syntax, rel values MUST be parsed into whitespace-separated tokens and MUST NOT be copied 1:1 into rel members of the link object.
  • each rel token that was produced during tokenization of the whitespace-separated native syntax is represented by one string in the value array.

native: http://example.org/; rel="start";
JSON: [ { "href":"http://example.org/", "rel":[ "start" ]} ]

native: http://example.org/; rel="start home";
JSON: [ { "href":"http://example.org/", "rel":["start", "home" ] } ]

CASE 2 - Target Attributes, Serialization Defined, Token-style, Not Repeatable

=> applies to: title, type, media

  • the attribute value MUST be represented as a string

native: http://example.org/; rel="start"; title="this"
JSON: [ { "href":"http://example.org/", "rel":[ "start" ] , title:"this"} ]

CASE 3 - Target Attributes, Serialization Defined, Token-style, Repeatable

=> applies to: hreflang

APPROACH — — array of attribute values

PATTERN — — “hreflang” : [“language”]
PATTERN — — “hreflang” : [“language” , “language”]

  • hreflang MUST be represented as an array of language tags
  • the parameter value of each occurrence of hreflang on a link in the native representation is mapped to one string in the value array

native: http://example.org/; rel="next"; hreflang="en de"
JSON: [ { "href":"http://example.org/", "rel":"next", "hreflang":["en","de"]

CASE 4 - Target Attributes, Serialization Defined, Token-star-style, Not Repeatable

=> applies to: title*

APPROACH — — array of attribute value & associated language

PATTERN — — “title*” : [“title” , “language”]

  • title* MUST be represented as an array of title and optional (?) language tag associated with the title

native: http://example.org/; rel="next"; title*="UTF-8'de'n%c3%a4chstes%20Kapitel"
JSON: [ { "href":"http://example.org/", "rel":"next", "title*":["nächstes Kapitel", "de"] } ]

CASE 5 - Target Attributes, Extension Attributes, Token-style, Unknown Repeatability

=> applies to e.g.: param

APPROACH — — array of one or more attribute values

PATTERN — — “param” : [“param-value”]
PATTERN — — “param” : [“param-value” , “param-value”]

  • each token-style extension attribute MUST be represented by an array in which each attribute value is represented as a distinct string
  • multiple occurrences of the same extension attribute on the same link result in multiple strings in the attribute value array

native: http://example.org/; rel="start"; param="x"
JSON: [ { "href":"http://example.org/", "rel":"start", "param":["x"] } ]

native: http://example.org/; rel="start"; param="x y"
JSON: [ { "href":"http://example.org/", "rel":"start", "param":["x y"] } ]

native: http://example.org/; rel="start"; param="x"; param="y"
JSON: [ { "href":"http://example.org/", "rel":"start", "param":["x","y"] } ]

CASE 6 - Target Attributes, Extension Attributes, Token-star-style, Unknown Repeatability

=> applies to e.g.: param*

APPROACH — — array of one or more arrays of attribute value & associated language

PATTERN — — param* : [[“param-value” , “language”]]
PATTERN — — param* : [[“param-value” , “language”] , [“param-value” , “language”]]

  • each token*-style extension attribute MUST be represented by an array
  • this array MUST contain one or more arrays, each of which MUST convey an attribute value and optional (?) language tag associated with that attribute value
  • this requires processors mapping from the native syntax to interpret the character encoding that the native syntax supports, and transcode the value accordingly. language tags also have to be extracted from the microsyntax and represented individually.

native: http://example.org/; rel="next"; x*="UTF-8'de'n%c3%a4chstes%20Kapitel"
JSON: [ { "href":"http://example.org/", "rel":"next", "x*":[["nächstes Kapitel", "de"]] } ]

@hvdsomp hvdsomp added the linkset label Aug 30, 2017

@dret

This comment has been minimized.

Copy link
Owner

dret commented Aug 30, 2017

case 1 is a mix of case 2 and case 3, right? it requires "post-processing" of the microsyntax, because the value is repeatable, but the attribute is not.
i toyed with the idea of describing such a "mapping framework", but it seemed a bit overkill to me because there are not that many more specific cases than there are general cases.
1-3 seem to work well just describing case by case. 4 and 6 do have some overlap and that's the best candidate (but the current draft does have a section dedicated to describing this pattern, so that's sort of covered). 5 is also covered by a dedicated section in the current draft.

@dret

This comment has been minimized.

Copy link
Owner

dret commented Aug 30, 2017

or did i misunderstand and this is just a summary write-up and not intended to go intro the draft? in that case no issue here: this covers the solutions described in the individual issues, so we're all good.

@handrews

This comment has been minimized.

Copy link

handrews commented Aug 30, 2017

@dret @hvdsomp I did define much of a mapping from HTTP headers to and from JSON at one point, and may well revive it depending on how we decide to handle hints in JSON Hyper-Schema: json-schema-org/json-schema-spec#296

@dret

This comment has been minimized.

Copy link
Owner

dret commented Aug 30, 2017

@handrews

This comment has been minimized.

Copy link

handrews commented Aug 30, 2017

@dret thanks! That looks extremely relevant :-) I really need to dig through the draft list more often and in more detail.

@asbjornu

This comment has been minimized.

Copy link

asbjornu commented Aug 31, 2017

@handrews:

I really need to dig through the draft list more often and in more detail.

No digging required. Just sign up for the relevant announcement list(s). :)

@hvdsomp

This comment has been minimized.

Copy link
Collaborator

hvdsomp commented Aug 31, 2017

@dret Allow me to clarify what I tried to do with the above:

  • Make the logic behind the choices made for the serialization explicit

  • Provide an overview of the JSON serialization as it currently stands

  • Following a suggestion you made a while ago when we were discussing the structure of the I-D, describe the JSON serialization following the structure of RFC5988bis:

  1. CASE 1 == Section 3.3. Relation Type (note that "rel" is not an attribute)
  2. CASES 2 through 4 == Section 3.4.1. Serialisation-Defined Attributes (the various cases pertain to the possible variations in the dimensions repeatability/non-repeatability and token/token*)
  3. CASES 5 and 6 == Section 3.4.2. Extension Attributes (the various cases pertain possible variations in the dimension token/token*; the dimension repeatability/non-repeatability does not play here because de-facto all is treated as repeatable)
  • I did not come from the perspective of how native links needs to be mapped to the JSON links. The reason being that the description provides an overview of the serialization per se. And that I assume JSON will also be used just by itself, without there ever being a native representation. Then again, I do very much agree that it would be good to include a description of the mapping in the I-D because there obviously will be cases where mapping will need to happen. Therefor, I did copy/past some wording you had in other Issues with that regard. Personally, I do however think that describing the JSON serialization and the native/JSON mapping are different things and - IMO - would not necessarily have to be described in the same section of the I-D.

hvdsomp added a commit that referenced this issue Sep 1, 2017

Significant edits re JSON serialization
Made edits in all sub-sections of 4.2 to reflect current syntax consensus as per #80.
Also updated Figure 8 to reflect syntax changes.
@hvdsomp

This comment has been minimized.

Copy link
Collaborator

hvdsomp commented Jan 14, 2019

I checked whether/how the above CASES 1 through 6 could be handled using the syntax proposed by @stain in a comment in #89. The result is below.

Comments:

  • It seems to me that all CASES can be covered by the syntax proposed by @stain. Double check welcome.
  • I like how the syntax rather elegantly expresses a set of links, i.e. a graph.
  • I love how the syntax always makes the link anchor explicit. This makes linkset documents more stand-alone/portable. In the serialization of the current I-D, anchor is optional but all examples make explicit use of it. This suggests that provision of the anchor is deemed important.
  • The rev (as opposed to rel) links can be addressed by directly expressing the inverse link, i.e. using the target of a rev link as anchor.
  • I see quite an advantage in that the syntax can be used "as is" in basic JSON scenarios and in JSON-LD scenarios by adding appropriate context (inline or via Link header).
  • In the JSON-LD case, I see an issue with so-called extension relation types, i.e. relation types not registered with IANA. In order to avoid misinterpretation, it seems those must be expressed as URIs in the JSON-LD case. That's also what @stain did in his example to avoid mapping an extension relation type to an IANA baseURL when applying context.
  • In the below, I did not use the approach with the embedding linkset as proposed in #103 but I am in favor of it for the reasons explained in that issue.

Here goes, assuming the link anchor is http://example.net/bar:

CASE 1

native: http://example.org/; rel="start";
JSON as per current I-D: [ { "href":"http://example.org/", "rel":[ "start" ]} ]
JSON as per Stian: [ { "anchor":"http://example.net/bar", "start":{"href":"http://example.org/"} ]

native: http://example.org/; rel="start home";
JSON as per current I-D: [ { "href":"http://example.org/", "rel":["start", "home" ] } ]
JSON as per Stian: [ { "anchor":"http://example.net/bar", "start":{"href":"http://example.org/"}, "home":{"href":"http://example.org/"} ]

Case 2:

native: http://example.org/; rel="start"; title="this"
JSON as per current I-D: [ { "href":"http://example.org/", "rel":[ "start" ] , title:"this"} ]
JSON as per Stian: [ { "anchor":"http://example.net/bar", "start":{"href":"http://example.org/", "title":"this"} ]

Case 3:

native: http://example.org/; rel="next"; hreflang="en de"
JSON as per current I-D: [ { "href":"http://example.org/", "rel":"next", "hreflang":["en","de"]
JSON as per Stian: [ { "anchor":"http://example.net/bar", "next":{"href":"http://example.org/", "hreflang":["en","de"] ]

Case 4:

native: http://example.org/; rel="next"; title*="UTF-8'de'n%c3%a4chstes%20Kapitel"
JSON as per current I-D: [ { "href":"http://example.org/", "rel":"next", "title*":["nächstes Kapitel", "de"] } ]
JSON as per Stian: [ { "anchor":"http://example.net/bar", "next":{"href":"http://example.org/", "title*":{ "@value": "nächstes Kapitel", "@language": "de" } ]

Case 5:

native: http://example.org/; rel="start"; param="x"
JSON as per current I-D: [ { "href":"http://example.org/", "rel":"start", "param":["x"] } ]
JSON as per Stian: [ { "anchor":"http://example.net/bar", "start":{"href":"http://example.org/", "param":["x"]} ]

native: http://example.org/; rel="start"; param="x y"
JSON as per current I-D: [ { "href":"http://example.org/", "rel":"start", "param":["x y"] } ]
JSON as per Stian: [ { "anchor":"http://example.net/bar", "start":{"href":"http://example.org/", "param":["x y"]} ]

native: http://example.org/; rel="start"; param="x"; param="y"
JSON: [ { "href":"http://example.org/", "rel":"start", "param":["x","y"] } ]
JSON as per Stian: [ { "anchor":"http://example.net/bar", "start":{"href":"http://example.org/", "param":["x","y"]} ]

Case 6:

native: http://example.org/; rel="next"; x*="UTF-8'de'n%c3%a4chstes%20Kapitel"
JSON: [ { "href":"http://example.org/", "rel":"next", "x*":[["nächstes Kapitel", "de"]] } ]
JSON as per Stian: [ { "anchor":"http://example.net/bar", "next":{"href":"http://example.org/", "x*":[{ "@value": "nächstes Kapitel", "@language": "de" }] ]

@dret

This comment has been minimized.

Copy link
Owner

dret commented Jan 22, 2019

just wondering: don't we have any examples with extension link relation types (i am just looking at the examples of case 1-6)? if that's the case, we should add one.

@hvdsomp

This comment has been minimized.

Copy link
Collaborator

hvdsomp commented Jan 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment