Skip to content

ActivityPub object

>>> from jsonschema import validate
>>> from tools import load_schema, dump
>>> from tools.activity_pub_object import *
>>> schema = load_schema("activity-pub-object")

Examples

These examples are taken from ActivityPub. We note that this specification contains quite a few invalid examples due to missing ids.

>>> validate(instance=examples["4_part"], schema=schema)
>>> validate(instance=examples["6_part"], schema=schema)
>>> validate(instance=examples["7_part"], schema=schema)
Example 4_part
{
    "type": "Note",
    "id": "https://chatty.example/ben/p/51085",
    "attributedTo": "https://chatty.example/ben/",
    "to": [
        "https://social.example/alyssa/"
    ],
    "inReplyTo": "https://social.example/alyssa/posts/49e2d03d-b53a-4c4c-a95c-94a6abf45a19",
    "content": "<p>Argh, yeah, sorry, I'll get it back to you tomorrow.</p><p>I was reviewing the section on register machines,since it's been a while since I wrote one.</p>"
}
Example 4_part
{
    "type": "Note",
    "id": "https://social.example/alyssa/posts/d18c55d4-8a63-4181-9745-4e6cf7938fa1",
    "attributedTo": "https://social.example/alyssa/",
    "to": [
        "https://social.example/alyssa/followers/",
        "https://www.w3.org/ns/activitystreams#Public"
    ],
    "content": "Lending books to friends is nice.  Getting them back is even nicer! :)"
}
Example 4_part
{
    "type": "Note",
    "id": "https://social.example/alyssa/posts/d18c55d4-8a63-4181-9745-4e6cf7938fa1",
    "attributedTo": "https://social.example/alyssa/",
    "to": [
        "https://social.example/alyssa/followers/",
        "https://www.w3.org/ns/activitystreams#Public"
    ],
    "content": "Lending books to friends is nice.  Getting them back is even nicer! :)"
}

Mastodon

>>> validate(instance=mastodon1, schema=schema)
Traceback (most recent call last): 
...
jsonschema.exceptions.ValidationError: None is not of type 'string'
...
Failed validating 'type' in schema['properties']['summary']:
    {'description': 'The summary of the object', 'type': 'string'}

On instance['summary']:
    None

After removing null values, it is valid.

>>> non_null = {k: v for k, v in mastodon1.items() if v}
>>> validate(instance=non_null, schema=schema)
Mastodon1
{
    "@context": [
        "https://www.w3.org/ns/activitystreams",
        {
            "ostatus": "http://ostatus.org#",
            "atomUri": "ostatus:atomUri",
            "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
            "conversation": "ostatus:conversation",
            "sensitive": "as:sensitive",
            "toot": "http://joinmastodon.org/ns#",
            "votersCount": "toot:votersCount",
            "quote": "https://w3id.org/fep/044f#quote",
            "quoteUri": "http://fedibird.com/ns#quoteUri",
            "_misskey_quote": "https://misskey-hub.net/ns#_misskey_quote",
            "quoteAuthorization": {
                "@id": "https://w3id.org/fep/044f#quoteAuthorization",
                "@type": "@id"
            },
            "gts": "https://gotosocial.org/ns#",
            "interactionPolicy": {
                "@id": "gts:interactionPolicy",
                "@type": "@id"
            },
            "canQuote": {
                "@id": "gts:canQuote",
                "@type": "@id"
            },
            "automaticApproval": {
                "@id": "gts:automaticApproval",
                "@type": "@id"
            },
            "manualApproval": {
                "@id": "gts:manualApproval",
                "@type": "@id"
            }
        }
    ],
    "id": "https://mastodon.social/users/the_milkman/statuses/115581506009919796",
    "type": "Note",
    "summary": null,
    "inReplyTo": null,
    "published": "2025-11-20T10:16:59Z",
    "url": "https://mastodon.social/@the_milkman/115581506009919796",
    "attributedTo": "https://mastodon.social/users/the_milkman",
    "to": [
        "https://www.w3.org/ns/activitystreams#Public"
    ],
    "cc": [
        "https://mastodon.social/users/the_milkman/followers"
    ],
    "sensitive": false,
    "atomUri": "https://mastodon.social/users/the_milkman/statuses/115581506009919796",
    "conversation": "tag:mastodon.social,2025-11-20:objectId=1193701442:objectType=Conversation",
    "context": null,
    "content": "<p>moo</p>",
    "contentMap": {
        "en": "<p>moo</p>"
    },
    "interactionPolicy": {
        "canQuote": {
            "automaticApproval": [
                "https://www.w3.org/ns/activitystreams#Public"
            ]
        }
    },
    "attachment": [],
    "tag": [],
    "replies": {
        "id": "https://mastodon.social/users/the_milkman/statuses/115581506009919796/replies",
        "type": "Collection",
        "first": {
            "type": "CollectionPage",
            "next": "https://mastodon.social/users/the_milkman/statuses/115581506009919796/replies?only_other_accounts=true&page=true",
            "partOf": "https://mastodon.social/users/the_milkman/statuses/115581506009919796/replies",
            "items": []
        }
    },
    "likes": {
        "id": "https://mastodon.social/users/the_milkman/statuses/115581506009919796/likes",
        "type": "Collection",
        "totalItems": 0
    },
    "shares": {
        "id": "https://mastodon.social/users/the_milkman/statuses/115581506009919796/shares",
        "type": "Collection",
        "totalItems": 0
    }
}