Skip to main content

ActivityStreams 2.0 Overview

ActivityStreams 2.0 is the vocabulary that ActivityPub uses to represent social data. It defines the format for activities, actors, objects, and collections using JSON-LD.

Specification​

The JSON-LD Context​

Every ActivityStreams document includes a context:

{
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Note",
"content": "Hello, world!"
}

The context maps short property names to full URIs:

  • type → https://www.w3.org/ns/activitystreams#type
  • content → https://www.w3.org/ns/activitystreams#content

Core Types​

Object​

The base type for all things:

{
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Object",
"id": "https://example.com/objects/1",
"name": "A simple object"
}

Activity​

An action performed by an actor:

{
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Create",
"actor": "https://example.com/users/alice",
"object": {
"type": "Note",
"content": "Hello!"
}
}

Actor​

An entity that can perform activities:

{
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Person",
"id": "https://example.com/users/alice",
"name": "Alice"
}

Collection​

A group of items:

{
"@context": "https://www.w3.org/ns/activitystreams",
"type": "Collection",
"totalItems": 2,
"items": [
{ "type": "Note", "content": "First" },
{ "type": "Note", "content": "Second" }
]
}

Type Hierarchy​

Object
├── Activity
│ ├── Create
│ ├── Delete
│ ├── Update
│ ├── Follow
│ ├── Accept
│ ├── Reject
│ ├── Like
│ ├── Announce
│ └── ... (more)
├── Actor
│ ├── Person
│ ├── Organization
│ ├── Application
│ ├── Service
│ └── Group
├── Object Types
│ ├── Note
│ ├── Article
│ ├── Image
│ ├── Video
│ ├── Audio
│ └── ... (more)
├── Collection
│ └── OrderedCollection
└── Link

Common Properties​

Identity​

PropertyTypeDescription
idURLUnique identifier
typeStringObject type
nameStringDisplay name
summaryStringShort description

Authorship​

PropertyTypeDescription
attributedToActorCreator
actorActorActivity performer

Content​

PropertyTypeDescription
contentStringMain content (HTML)
contentMapObjectLocalized content
mediaTypeStringMIME type

Timestamps​

PropertyTypeDescription
publishedDateTimeCreation time
updatedDateTimeLast modified
startTimeDateTimeEvent start
endTimeDateTimeEvent end

Addressing​

PropertyTypeDescription
toArrayPrimary recipients
ccArraySecondary recipients
btoArrayPrivate primary
bccArrayPrivate secondary

Extending ActivityStreams​

Custom Properties​

Add properties via the context:

{
"@context": [
"https://www.w3.org/ns/activitystreams",
{
"sensitive": "as:sensitive",
"toot": "http://joinmastodon.org/ns#",
"blurhash": "toot:blurhash"
}
],
"type": "Note",
"content": "Hidden content",
"sensitive": true
}

Custom Types​

Define new types:

{
"@context": [
"https://www.w3.org/ns/activitystreams",
{
"Emoji": "toot:Emoji"
}
],
"type": "Emoji",
"name": ":awesome:",
"icon": {
"type": "Image",
"url": "https://example.com/emoji/awesome.png"
}
}

Processing ActivityStreams​

Parsing​

function parseActivityStreams(json) {
// Normalize to array context
let context = json['@context'];
if (!Array.isArray(context)) {
context = [context];
}

// Get type
const type = json.type;

// Handle multiple types
const types = Array.isArray(type) ? type : [type];

return {
context,
types,
data: json
};
}

Type Checking​

function isActivity(obj) {
const activityTypes = [
'Create', 'Update', 'Delete', 'Follow',
'Accept', 'Reject', 'Like', 'Announce', 'Undo'
];
return activityTypes.includes(obj.type);
}

function isActor(obj) {
const actorTypes = [
'Person', 'Organization', 'Application', 'Service', 'Group'
];
return actorTypes.includes(obj.type);
}

See Also​