4.4 KiB
+++ date = 2024-10-23T23:01:00-05:00 tags = [] draft = true summary = "> JsonLD is not the optimal solution to ActivityPub’s problem [...] Why? Because parsing it is hell.\n\nThe problem here is with AS2, not with JSON-LD. The majority of AS2 properties can be a string, a reference, an object, or an array of any of these. AS2 forces everyone to handle every possibility, instead of being explicit and serializing objects as actual JSON objects. Consider the following scenario where you want to display someone's avatar -- a pretty basic task. Here's what you have to deal with:" params.inReplyTo name = "post #131 of "Desired changes for a future revision of ActivityPub and ActivityStreams"" url = "https://socialhub.activitypub.rocks/t/desired-changes-for-a-future-revision-of-activitypub-and-activitystreams/4534/131" params.syndication name = "Original post on SocialHub" url = "https://socialhub.activitypub.rocks/t/desired-changes-for-a-future-revision-of-activitypub-and-activitystreams/4534/133" +++
JsonLD is not the optimal solution to ActivityPub’s problem [...] Why? Because parsing it is hell. {cite="https://socialhub.activitypub.rocks/t/desired-changes-for-a-future-revision-of-activitypub-and-activitystreams/4534/131" card="socialhub.activitypub.rocks/Laxystem"}
The problem here is with AS2, not with JSON-LD. The majority of AS2 properties can be a string, a reference, an object, or an array of any of these. AS2 forces everyone to handle every possibility, instead of being explicit and serializing objects as actual JSON objects.
Consider the following scenario where you want to display someone's avatar -- a pretty basic task. Here's what you have to deal with:
{
"icon": "https://something.example/icon" // is this a Link node, or an Image object, or a URI to the resource?
}
{
"icon": {
"type": "Link",
"name": "Avatar"
"href": "https://something.example/icon",
"width": 400,
"height": 400,
"mediaType": "image/png"
}
}
{
"icon": [
{
"type": "Link",
"name": "Avatar, full size"
"href": "https://something.example/icon",
"width": 400,
"height": 400,
"mediaType": "image/png"
},
{
"type": "Link",
"name": "Avatar, profile size"
"href": "https://something.example/icon?resize=120",
"width": 120,
"height": 120,
"mediaType": "image/png"
},
{
"type": "Link",
"name": "Avatar, timeline size"
"href": "https://something.example/icon?resize=48",
"width": 48,
"height": 48,
"mediaType": "image/png"
}
]
}
{
"icon": {
"id": "https://something.example/icon"
"type": "Image",
"name": "My avatar",
"summary": "Image description goes here",
"url": "https://something.example/icon.png"
}
}
{
"icon": {
"id": "https://something.example/icon"
"type": "Image",
"name": "My avatar",
"summary": "Image description goes here",
"url": [
"https://something.example/some-uri", // is this a direct resource URI or a Link?
{
"href": "https://something.example/icon.jpg" // no mediaType, so you have to guess based on file extension
},
{
"href": "https://something.example/icon.png" // no mediaType, so you have to guess based on file extension
},
{
"href": "https://something.example/icon.avif" // no mediaType, so you have to guess based on file extension
},
{
"href": "https://something.example/icon.jxl" // no mediaType, so you have to guess based on file extension
}
]
}
}
All of these are generally valid by AS2. So the consumer now has to be able to parse multiple representations instead of just one. And even after parsing, you still have to figure out what to do with the information that you parsed!
If anything, JSON-LD can simplify things, by allowing you to effectively "normalize" the data beforehand, so that you have less possibilities to deal with. Everything becomes an array of JSON objects. You still have problems because of AS2 (for example, knowing if any given @id
is a resource, Link, or Image), but you eliminate a lot of potential cases. Your logic doesn't need to handle bare strings or singular objects anymore; you only need to loop over the array and pluck whichever JSON object matches your criteria. Which, again, your complications beyond this point are the fault of AS2.