Activity Streams 2.0

At long last, the Activity Streams 2.0 specification is nearing W3C Candidate Recommendation stage. Hopefully the CR will post sometime next week.

As a reminder, Activity Streams is a JSON syntax for describing Activity (social or otherwise). For instance, the expression, “Krista added a photo to an album” can be represented using JSON such as:

"@context": "",
"actor": {
"id": "",
"name": "Krista",
"type": "Person"
"type": "Add",
"object": {
"id": "",
"type": "Image",
"name": "Picture of my Cat",
"url": ""
"target": {
"id": "",
"name": "My Cat Pics",
"url": ""

The Activity Streams 2.0 specification comes in two parts:

The Core specification describes the JSON serialization, while the Vocabulary specification defines the object types and properties that can be represented.

What’s New in AS 2.0?

The first version of the Activity Streams specification was published in 2011 at The 2.0 version represents a significant evolution that provides:

  • Improved Internationalization with explicit language context and bidirectional text support;
  • Improved Extensibility via JSON for Linked Data support;
  • Optionally Ordered Collections and built-in support for paging;
  • Support for Intransitive (or Object-less) Activities (e.g. Activities where the Actor is also the Object, like “Joe is traveling”);
  • A first-class Link model;
  • 28 built-in common types of Activities;
  • 13 built-in common types of Objects, including a Tombstone type used to represent deleted objects, and a Relationship type used to represent social network relationships;
  • Built-in audience targeting (this was previously an extension to Activity Streams 1.0);
  • Built-in geotagging;
  • The ability to identity both the origin and destination of an Activity (e.g. “Aaron moved the document from Folder A to Folder B”);
  • The ability to describe the result of an Activity;
  • And much more…

How can I use it?

If you use Node.js, then you can use the JavaScript implementation I’ve put together. Simply do:

$ npm install

The module supports the production and consumption of Activity Streams 2.0 objects but it does not do any persistence on it’s own. To create an Activity:

const as = require('');
const activity = as.add()
.name('Picture of my Cat')
.name('My Cat Pics')

To serialize the `activity` object as JSON, call either the `write()` or `prettyWrite()` method:

activity.prettyWrite((err, doc) => {
if (err) throw err;
console.log(doc); // doc will be a string

Note that the `write()` and `prettyWrite()` methods are async only because there’s some JSON-LD stuff going on under the covers that requires async handling.

Parsing a serialized Activity is straightforward. The following example shows parsing using a stream:

const as = require('');
const fs = require('fs');
const AS2Stream = as.Stream;
const path = require('path');
const through = require('through2');
.pipe(new AS2Stream())
.pipe(through.obj((obj,encoding,callback) => {

View the modules for more API details.

Like what you read? Give James M Snell a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.