-
Notifications
You must be signed in to change notification settings - Fork 16
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
Linked JSON: Why link
?
#78
Comments
I agree with this, and prefer |
Thank you for these comments! However, I actually do prefer the basic It is true that we programmers often prefix special variables with "unusual characters" so that they stand out. However, in this spec, the only thing special is the field I also acknowledge Ben's concern that:
It's true that uninitiated programmers won't know that there is anything special about links. However, the uninitiated programmer will not understand most fields in a JSON object they encounter. I don't see a link as being any different in this respect. Can you give an example where it's particularly dangerous for an uninitiated programmer to encounter a Second, I want to call attention to the longer-term costs of cluttering the syntax that we use in the basic web platform. It takes only a few seconds to learn that |
Indeed, that example would probably be better as application/linked-json. But it's also true that linked-json is still valid json. Whether it's a bug depends on the application. Maybe we need a specific example here?
I wouldn't say that it requires a converter, as Linked JSON is still valid JSON. Perhaps you are thinking about a specific case where you want to inline the links into the JSON document? I'm not sure what the issue is here, in any case. |
I appreciate your comments @toomim, but I also share that I would ask again that I am unsure why we are doing one more standard and not simply have JSON-LD, but that is a separate discussion I will not reopen here. :-) To me it looks like Linked JSON is just a special case of JSON-LD (with |
@toomim Here's another consideration that I think is important: the most common use of JSON is as a serialization of data. So for example, say you have a "LinkedItem" class in some Javascript code (or Python, Ruby etc.), and you want to serialize it. The most natural thing to do is to lean on existing tools, such as class LinkedItem {
constructor(id, data, link) {
this.id = id;
this.data = data;
this.link = link;
}
}
const n1 = new LinkedItem(1, "hi", null);
const n2 = new LinkedItem(2, "ok", 1);
console.log("n1", JSON.stringify(n1));
/* {"id":1,"data":"hi","link":null} */
console.log("n2", JSON.stringify(n2));
/* {"id":2,"data":"ok","link":1} */ Since "link" is a common key, it seems like Linked JSON has a bad surprise in store for the developer: Do what you usually do when serializing data, but every once in a while, the semantics of your serialized data will not match your intention. We can greatly reduce the likelihood of this "bad surprise" by adding a special character prefix, since it never (almost never?) occurs that a data object's keys start with a |
@mitar and @canadaduane, I think you have in mind use-cases that this spec is not designed for. This is not a serialization format for application data structures. This is a language for annotating hypermedia resources with links. In other words, this is a Hypermedia JSON with Transclusion. It is appropriate only for data that tries to model Transclusions. If you want to serialize data structures, use JSON. Linked JSON is not for serialization. If you want to program with linked hypermedia resources, then Linked JSON is useful. Linked JSON is a language, like JSON or Javascript. When you use Linked JSON, you'll know you are using it, and will know what The JSON-LD language is designed with different goals, and has design flaws for a general-purpose programming. JSON-LD does not support arrays, for instance: Duane: Linked JSON actually causes no bug in your example above, because it is doesn't impact serialization. You can serialize and parse with the regular JSON.serialize() and JSON.parse() functions. This spec is only for the people who want to use it. We cannot force people to use a spec. That is not what the IETF does. The IETF is a space for people who want to interoperate to find consensus on how to do so. What use-cases are you wanting to make interoperable? I'll list some of mine below. Linked JSON is useful for building development tools. For instance, it lets you implement a JSON viewer that lets you click on a link to load it inline, because your tools will know which things are links. But an even cooler feature IMO is in Statebus— it can transclude links transparently as you access them in Javascript, loading them like variables behind the scenes over the network. For example, if you have this data structure: # /posts
[
{link: "/post/3"},
..
]
# /post/3
{
author: {link: "/user/john"},
title: "Hi mom!",
body: "I am really excited to see you!"
}
# /user/john
{
name: "Johnny Appleseed",
job_title: "Inventor",
pic: {link: "/images/seeds.jpg"}
} Then Statebus lets you read and write data across networked links transparently, like this: state["/posts"][0].name = "The Rock" This single line traversed 3 networked resources! This is soooo awesome to program with. Your network totally disappears! (Under the hood, Statebus uses ES6 Proxies and reactive functions. And be aware this feature is still marked "experimental" in Statebus.) This is what Linked JSON enables. Finally, I want to point out that This is unnecessary. This is three layers of escaping. What an ugly syntax. I've been writing Linked JSON code for 6 years or so (except we use the term So if you use Linked JSON, we need to recommend using an abstraction that automatically escapes links to prevent Cross-Site Linking; just like HTML views escape html to prevent Cross-Site Scripting. Linked JSON can be escaped an unescaped with 13 lines of Javascript: var escape_links = json =>
recurse(json, k => (k === 'link' || k[0] === '_') ? `_${k}` : k)
var unescape_links = json =>
recurse(json, k => k[0] === '_' ? k.substr(1) : k)
var recurse = (json, f) => {
// Recurse on arrays
if (Array.isArray(json))
return json.map((x) => recurse(x, f))
// Escape links in objects
if (typeof json === 'object')
return Object.fromEntries(Object.entries(json).map(
([k, v]) => [f(k), recurse(v, f)]
))
// Else it's just an atom
return json
} If we used JSON-LD this escaping/unescaping code would be much more complex. In the long run I suggest implementing the spec to get experience:
|
I think I can articulate the problem here, and show why it is not desirable to have two formats that are indistinguishable except for a header:
Here are some examples of JSON (or is it Linked JSON?) in other code bases. These developers have some assumptions around what "link" means, but the only context they have provided to a casual observer is in the semantics of their native languages or the structure & keys of their JSON:
|
I'm sorry Duane, but I still don't see what the problem is. I see a bunch of JSON snippets where the word "link" appears, but I don't see an articulated scenario where they cause a problem for a user or programmer. Are you imagining that these programmers accidentally serve their data with Anyway, are you thinking about a misconfiguration? Or something else? |
I'm advocating for human learning. These are examples of JSON existing outside of the context of an HTTP message. Human beings browser these repositories and learn from each other. Having multiple "indicators" of meaning--or at least tip-offs that trigger one to question one's assumptions when viewing code--is helpful to humans. |
We should probably be wary of bikeshedding here. I care about human learning too, but I don't see any clear evidence that If we kept going, I'd argue that But these arguments could go back and forth forever, and in the end we are just arguing over variable naming conventions. |
I give up.
…On Fri, Feb 26, 2021 at 12:19 AM Michael Toomim ***@***.***> wrote:
We should probably be wary of bikeshedding
<https://www.urbandictionary.com/define.php?term=bikeshedding> here.
I care about human learning too, but I don't see any clear evidence that
$link is better than link for learning that a field is a link. Nor do I
see any concrete bugs caused by link.
If we kept going, I'd argue that link is probably better than $link for
learning because it's simpler to read, and doesn't imply that there is
something special about dollar signs that the reader doesn't know about.
For instance, if the user saw $name, they might think it's special in the
same way as $link, but it's not. They might escape any user-inputted
field that begins with a $, and then expect a Linked JSON parser to
unescape it, but that won't happen, and this can lead to bugs where field
names become corrupted.
But these arguments could go back and forth forever, and in the end we are
just arguing over variable naming conventions.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#78 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAABAIV5EXBXBKSMKPDQRLTA5DORANCNFSM4WI2TRTA>
.
|
Mike & I spoke offline. We agree this is less important than other things right now. Our style is different, and may remain so. But if there's something new that comes up in future around this then it may be worth my revisiting it. In the meantime, we'll focus on other more pressing parts of the spec. I was also concerned that the parameters for "winning an argument" are unclear, and Mike will post some guidelines about how, in general, we can reach decisions via rough consensus (this will likely reflect IETF guidelines). |
Thanks Duane. I've been taking some notes on the IETF process for for consensus here: https://braid.org/consensus Some of the linked documents describe what to do when people get stuck in arguments. |
My concern with
link
is that:link
withapplication/json
instead ofapplication/linked-json
, they have to wonder if that was a bug? Such as this situation here: https://github.com/braid-work/braid-spec/blob/bf179d8c84ea48b5cb1ea4faf23c6ea9bfc28416/draft-toomim-httpbis-braid-http-03.txt#L289-L290link
field in them.When reading the cited benefits of
$ref
. One could do$link
, to denote to the reader that it is meant to be something special, while enabling escaping via$$link
or\\$link
; with\\$link
being something intuitive to the ECMAScript world, as is done in such cases as constructing regular expressions with stringsnew RegExp(".\\..")
(as opposed to/.\../
) to look for three characters, the middle one dot.The text was updated successfully, but these errors were encountered: