In ActivityPub, these are all equivalent:
"type":"Banana"
"type":["Banana"]
"type":{"@ID":"Banana"}
"type":[{"@ID":"Banana"}]
"type":{"id":"Banana"}
"type":[{"id":"Banana"}]
"@type":"Banana"
"@type":["Banana"]
"@type":{"@ID":"Banana"}
"@type":[{"@ID":"Banana"}]
"@type":{"id":"Banana"}
"@type":[{"id":"Banana"}]
#ActivityPub #ActivityStreams #FediDev #JSONLD
@reiver@mastodon.social That’s not true. Most of those are not correct AS2. Only ‘"type": “Banana"’ is correct.
Activity Streams says, The serialized JSON form of an Activity Streams 2.0 document MUST be consistent with what would be produced by the standard JSON-LD 1.0 Processing Algorithms and API [JSON-LD-API] Compaction Algorithm using, at least, the normative JSON-LD @context definition provided here.
So, assuming that you’ve defined some Banana extension, your full code might look like this:
If you park all that context data at a context URL, you can have a much slimmer payload:
If you don’t define the extra context stuff, you have to use the full URL for the type:
I prefer the slim one with the context URL.
If you use a JSON-LD library for parsing your input, all the funky variants you’re sharing get canonicalized into one easy-to-use one. And if you use it for formatting your output, you’ll always produce nice, clean AS2.
Oh, and if you’re using an AS2 type, you don’t have to worry about the extra context URL, obvs: