JSON-LD Framing

Hi all,
is there anybody outsite, who is working with JSON-LD Framing?
Can we find Framing settings, that is more or less able to generate a “compatible” version of RDF for other activity-pub servers?

Can you say more - what would you like to do with framing?

It’s a newer technique in JSON-LD that lets you put a frames or shapes inside a document. It’s quite a bit more complexity but has certain esoteric use cases. Unless you have a good reason to use them, I would avoid them. AP isnt fully compatible with JSON-LD yet, so advanced features might be learning curve, and also a challenge to get upstream.

My AP implementation works with a triple store. So deliver rdf objects in turtle or “real”-json-ld is not a problem, until the library i’m using supports the format in a correct way.

if it is possible to find json-ld framing settings to produce json-ld that is understandable for “all” AP Servers/Clients, then that would be a dream.

Ohhh I see. Yeah, not sure something like that exists currently. You should create a repo / project for it!

I think:

{
  "@context": "https://www.w3.org/ns/activitystreams", 
  "type": "Create"
}

works as a frame to turn something that has the expected data for a create activity into what most Fediverse applications expect.

See JSON-LD Playground

There’s a long list of caveats to this. For example you should probably not include the Actor object in the graph the frame is applied to. Similarly, the object should probably be included. For other base activities just replace “Create” by something appropriate. If you use Hashtags, you should define them in the @context.

Hi all,
need help.

i’ve the following turtle:

@prefix : <https://www.w3.org/ns/activitystreams#> .
@prefix schema: <http://schema.org/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix RDFPUB: <http://rdf-pub.org#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ldp: <http://www.w3.org/ns/ldp#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ns2: <http://purl.org/dc/terms/> .
@prefix ns1: <http://www.w3.org/2004/02/skos/core#> .

<http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d> a :Person;
  owl:sameAs <http://localhost:8081/575ee2c9-e12e-4148-9c8b-920724c670e7>;
  schema:identifier "f0fea745-f6a7-455f-bec4-62f7aec32948";
  schema:version 1;
  RDFPUB:outboxSparql <http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/outbox/sparql>;
  RDFPUB:oauth2IssuerUserId "4722@example.com";
  :name "JvPBpQUpPA";
  ldp:inbox <http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/inbox>;
  RDFPUB:oauth2Issuer "http://example.com";
  :endpoints _:c94d7e830da14b5bb61e1c738f8f74b9216;
  RDFPUB:oauth2IssuerPreferredUserName "JvPBpQUpPA@example.com";
  RDFPUB:inboxSparql <http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/inbox/sparql>;
  :published "2024-01-13T12:22:01.092+01:00";
  :outbox <http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/outbox> .

_:c94d7e830da14b5bb61e1c738f8f74b9216 a :Object;
  :oauthAuthorizationEndpoint <https://login.m4h.network/auth/realms/LOA/protocol/openid-connect/auth>;
  :oauthTokenEndpoint <https://login.m4h.network/auth/realms/LOA/protocol/openid-connect/token> .

i convert it into json-ld:

[
  {
    "@id": "_:b0",
    "@type": [
      "https://www.w3.org/ns/activitystreams#Object"
    ],
    "https://www.w3.org/ns/activitystreams#oauthAuthorizationEndpoint": [
      {
        "@id": "https://login.m4h.network/auth/realms/LOA/protocol/openid-connect/auth"
      }
    ],
    "https://www.w3.org/ns/activitystreams#oauthTokenEndpoint": [
      {
        "@id": "https://login.m4h.network/auth/realms/LOA/protocol/openid-connect/token"
      }
    ]
  },
  {
    "@id": "http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d",
    "@type": [
      "https://www.w3.org/ns/activitystreams#Person"
    ],
    "http://www.w3.org/2002/07/owl#sameAs": [
      {
        "@id": "http://localhost:8081/575ee2c9-e12e-4148-9c8b-920724c670e7"
      }
    ],
    "http://schema.org/identifier": [
      {
        "@value": "f0fea745-f6a7-455f-bec4-62f7aec32948"
      }
    ],
    "http://schema.org/version": [
      {
        "@value": 1
      }
    ],
    "http://rdf-pub.org#outboxSparql": [
      {
        "@id": "http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/outbox/sparql"
      }
    ],
    "http://rdf-pub.org#oauth2IssuerUserId": [
      {
        "@value": "4722@example.com"
      }
    ],
    "https://www.w3.org/ns/activitystreams#name": [
      {
        "@value": "JvPBpQUpPA"
      }
    ],
    "http://www.w3.org/ns/ldp#inbox": [
      {
        "@id": "http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/inbox"
      }
    ],
    "http://rdf-pub.org#oauth2Issuer": [
      {
        "@value": "http://example.com"
      }
    ],
    "https://www.w3.org/ns/activitystreams#endpoints": [
      {
        "@id": "_:b0"
      }
    ],
    "http://rdf-pub.org#oauth2IssuerPreferredUserName": [
      {
        "@value": "JvPBpQUpPA@example.com"
      }
    ],
    "http://rdf-pub.org#inboxSparql": [
      {
        "@id": "http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/inbox/sparql"
      }
    ],
    "https://www.w3.org/ns/activitystreams#published": [
      {
        "@value": "2024-01-13T12:22:01.092+01:00"
      }
    ],
    "https://www.w3.org/ns/activitystreams#outbox": [
      {
        "@id": "http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/outbox"
      }
    ]
  },
  {
    "@id": "http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/inbox"
  },
  {
    "@id": "http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/inbox/sparql"
  },
  {
    "@id": "http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/outbox"
  },
  {
    "@id": "http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/outbox/sparql"
  },
  {
    "@id": "http://localhost:8081/575ee2c9-e12e-4148-9c8b-920724c670e7"
  },
  {
    "@id": "https://login.m4h.network/auth/realms/LOA/protocol/openid-connect/auth"
  },
  {
    "@id": "https://login.m4h.network/auth/realms/LOA/protocol/openid-connect/token"
  },
  {
    "@id": "https://www.w3.org/ns/activitystreams#Object"
  },
  {
    "@id": "https://www.w3.org/ns/activitystreams#Person"
  }
]

and then do campacting: sample

any idea what i’ve to do, that it is readable for the json only guys ?

It looks like the compaction algorithm doesn’t automatically embed the blank node in the endpoints property of the Person object since it’s not embedded in the expanded data.

Some ideas (maybe there a better ones…):

  • Embed the blank node in the endpoints property prior to compaction. Maybe whatever turtle-to-jsonld converter code you’re using has an option for this behavior? This will eliminate the top-level @graph list.
  • (Optional) After embedding it, remove the blank node identifier from the endpoints data (it’s implied if there is no @id).
  • (Optional) Remove the Object type from the embedded endpoints data. It probably doesn’t hurt anything, but it’s not an as2:Object.
  • The data type in the RDF/Turtle data for as:published is incorrect. It should be an “xsd:dateTime” but the JSON-LD default is to treat it as a string without a specified type. This will cause the compactor to use as:published instead of published as the compacted key for that data. I added "@type": "http://www.w3.org/2001/XMLSchema#dateTime" to the expanded published value so it will compact the way you want.
  • (Optional) Move the activitystreams context document URL to the end of the list. This is not explicitly addressed in the AS2 Recommendation, but this will ensure that none of the other non-AS2 context terms silently override the AS2 terms (which are not protected). The last term definition wins in JSON-LD (except for protected terms, which would trigger an error message).

JSON-LD Playground

That’s terrible. that means i always have to correct the result of my turtle → json. i use rdf4j for converting rdf and jsonld-java for the compact.

And that means that the expected activity-pub json cannot be generated with standard json-ld generators from rdf, since it is not compatible to the json-ld specification?

btw. you found a bug :wink: i’ve special handlich for dates, but it was missing at one place. no the turtle has “http://www.w3.org/2001/XMLSchema#dateTime”.

ActivityStreams Section 2 says “An Activity Streams Document is a JSON document whose root value is an Activity Streams Object of any type, including a Collection, and whose MIME media type is " application/activity+json”."

Your object is compacted, but it’s not properly rooted. You need to figure out how to use your library to properly specify the root value of your outputted document, prior to compaction. I’m not an expert in JSON-LD processing algorithms and I’ve never used jsonld-java, so I would suggest contacting the library author for advice.

i think i have solved the problem for Blank Node references. i convert object by object and build the “json” myself.

I’m more worried about the date at the moment. I’m sure I can solve that for the AS namespace.

But taking all namespaces into account will be a challenge that I will postpone until later. If you want to be able to process all kinds of rdf data, then little things like that cause big problems.

It stays exciting

I’m not sure that’s the case (I haven’t used rdf4j). I do see the following option:

Have you tried that?

Either way, the expanded JSON-LD is compatible with the JSON-LD specification, but AS2 JSON-LD is a special “profile” of JSON-LD with some restrictions (like @nightpool mentioned) to make it easier to use as plain JSON.

(Edit: our messages crossed, so maybe you’ve already solved this a different way?)

1 Like

GGGrrrrrrrrr. i think i missunderstand your message. Is that valid:

{
  "@context": [
    "https://schema.org/docs/jsonldcontext.json",
    "https://rdf-pub.org/schema/rdf-pub-context.json",
    "https://www.w3.org/ns/activitystreams"
  ],
  "id": "http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d",
  "type": "Person",
  "inbox": "http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/inbox",
  "endpoints": {
    "oauthAuthorizationEndpoint": "https://login.m4h.network/auth/realms/LOA/protocol/openid-connect/auth",
    "oauthTokenEndpoint": "https://login.m4h.network/auth/realms/LOA/protocol/openid-connect/token"
  },
  "name": "JvPBpQUpPA",
  "outbox": "http://localhost:8081/1a6f7dd1-fecb-4d15-9fd7-61499e560a2d/outbox",
  "published": "2024-01-13T12:22:01.092+01:00"
}

i thought i had to explicitly name the type “http://www.w3.org/2001/XMLSchema#dateTime”. but that is already defined in the context. the problem was only the as:

another day comes to an end :see_no_evil:

unfortunately, the JSONLDSettings are deprecated. i have asked whether there is a successor option.
My own solution now generates the following:

{
  "id" : "http://localhost:8081/651b3e0d-83c1-4682-aed2-64712f3e4753",
  "type" : "Person",
  "inboxSparql" : "http://localhost:8081/651b3e0d-83c1-4682-aed2-64712f3e4753/inbox/sparql",
  "rdfpub:oauth2Issuer" : "http://example.com",
  "rdfpub:oauth2IssuerPreferredUserName" : "LVEBrQJDvs@example.com",
  "rdfpub:oauth2IssuerUserId" : "3117@example.com",
  "outboxSparql" : "http://localhost:8081/651b3e0d-83c1-4682-aed2-64712f3e4753/outbox/sparql",
  "identifier" : "532592e2-84f7-4995-831c-0755360863c6",
  "version" : {
    "type" : "xsd:integer",
    "@value" : "1"
  },
  "owl:sameAs" : {
    "id" : "http://localhost:8081/8c689b5c-4d02-4883-b757-98715e02228e"
  },
  "inbox" : "http://localhost:8081/651b3e0d-83c1-4682-aed2-64712f3e4753/inbox",
  "endpoints" : {
    "oauthAuthorizationEndpoint" : "https://login.m4h.network/auth/realms/LOA/protocol/openid-connect/auth",
    "oauthTokenEndpoint" : "https://login.m4h.network/auth/realms/LOA/protocol/openid-connect/token"
  },
  "name" : "LVEBrQJDvs",
  "outbox" : "http://localhost:8081/651b3e0d-83c1-4682-aed2-64712f3e4753/outbox",
  "published" : "2024-01-13T18:59:11.469+01:00",
  "@context" : [ "https://schema.org/docs/jsonldcontext.json", "https://rdf-pub.org/schema/rdf-pub-context.json", "https://www.w3.org/ns/activitystreams" ]
}

That looks good to me.

1 Like

yes, this document looks great. The follow-up document you posted also looks fine

1 Like