json+jd format

20 views
Skip to first unread message

rdf 4j

unread,
Mar 25, 2021, 6:02:31 AMMar 25
to rdf4j...@googlegroups.com

i’m afraid the json guys will curse me if i give them the following json+ld. so the question is, can this somehow be rendered into a more json human readable form?
As a sample i useed 1) from the activityPub Specification. Convert it to turtle 2). and take 2) and convert it back to jsonld 3)
3) scares me a little ;-)


1) original:

{
  "@context": "https://www.w3.org/ns/activitystreams",
  "summary": "Sally's notes",
  "type": "OrderedCollection",
  "totalItems": 2,
  "orderedItems": [
    {
      "type": "Note",
      "name": "A Simple Note"
    },
    {
      "type": "Note",
      "name": "Another Simple Note"
    }
  ]
}

2) converted to turtle (Rio.parse, Rio.write)

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix as: <https://www.w3.org/ns/activitystreams#> .
@prefix ldp: <http://www.w3.org/ns/ldp#> .
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .

_:genid-8e833aa393f04806ba838ee44fb57aa8-b0 a as:OrderedCollection;
  as:items _:genid-8e833aa393f04806ba838ee44fb57aa8-b3;
  as:summary "Sally's notes";
  as:totalItems "2"^^xsd:nonNegativeInteger .

_:genid-8e833aa393f04806ba838ee44fb57aa8-b3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first>
    _:genid-8e833aa393f04806ba838ee44fb57aa8-b1;
  <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:genid-8e833aa393f04806ba838ee44fb57aa8-b4 .

_:genid-8e833aa393f04806ba838ee44fb57aa8-b4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first>
    _:genid-8e833aa393f04806ba838ee44fb57aa8-b2;
  <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .

_:genid-8e833aa393f04806ba838ee44fb57aa8-b1 a as:Note;
  as:name "A Simple Note" .

_:genid-8e833aa393f04806ba838ee44fb57aa8-b2 a as:Note;
  as:name "Another Simple Note" .

3) converted back to jsonld (Rio.parse, Rio.write)

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix as: <https://www.w3.org/ns/activitystreams#> .
@prefix ldp: <http://www.w3.org/ns/ldp#> .
@prefix vcard: <http://www.w3.org/2006/vcard/ns#> .

_:genid-8e833aa393f04806ba838ee44fb57aa8-b0 a as:OrderedCollection;
  as:items _:genid-8e833aa393f04806ba838ee44fb57aa8-b3;
  as:summary "Sally's notes";
  as:totalItems "2"^^xsd:nonNegativeInteger .

_:genid-8e833aa393f04806ba838ee44fb57aa8-b3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first>
    _:genid-8e833aa393f04806ba838ee44fb57aa8-b1;
  <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:genid-8e833aa393f04806ba838ee44fb57aa8-b4 .

_:genid-8e833aa393f04806ba838ee44fb57aa8-b4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first>
    _:genid-8e833aa393f04806ba838ee44fb57aa8-b2;
  <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .

_:genid-8e833aa393f04806ba838ee44fb57aa8-b1 a as:Note;
  as:name "A Simple Note" .

_:genid-8e833aa393f04806ba838ee44fb57aa8-b2 a as:Note;
  as:name "Another Simple Note" .
[ {
  "@id" : "_:genid-538b1f4d46ba4971bd2f19998126d2bb-792493C5646D70B1BA5E7441CD554626",
  "@type" : [ "https://www.w3.org/ns/activitystreams#Note" ],
  "https://www.w3.org/ns/activitystreams#name" : [ {
    "@value" : "A Simple Note"
  } ]
}, {
  "@id" : "_:genid-538b1f4d46ba4971bd2f19998126d2bb-AF51D26AF62D8D74BD8EED8B9C33E425",
  "@type" : [ "https://www.w3.org/ns/activitystreams#Note" ],
  "https://www.w3.org/ns/activitystreams#name" : [ {
    "@value" : "Another Simple Note"
  } ]
}, {
  "@id" : "_:genid-538b1f4d46ba4971bd2f19998126d2bb-CA3F72750972911EC4FFBD740581C379",
  "@type" : [ "https://www.w3.org/ns/activitystreams#OrderedCollection" ],
  "https://www.w3.org/ns/activitystreams#items" : [ {
    "@list" : [ {
      "@id" : "_:genid-538b1f4d46ba4971bd2f19998126d2bb-792493C5646D70B1BA5E7441CD554626"
    }, {
      "@id" : "_:genid-538b1f4d46ba4971bd2f19998126d2bb-AF51D26AF62D8D74BD8EED8B9C33E425"
    } ]
  } ],
  "https://www.w3.org/ns/activitystreams#summary" : [ {
    "@value" : "Sally's notes"
  } ],
  "https://www.w3.org/ns/activitystreams#totalItems" : [ {
    "@type" : "http://www.w3.org/2001/XMLSchema#nonNegativeInteger",
    "@value" : "2"
  } ]
} ]

rdf 4j

unread,
Mar 25, 2021, 7:32:29 AMMar 25
to rdf4j...@googlegroups.com

Sorry, there was an error in the second json ld box:

[ {
  "@id" : "_:genid-d893965296094717aa17b315578e9694-0BEE8A4ED89FAB5FF8EB0ED84DC33231",
  "@type" : [ "https://www.w3.org/ns/activitystreams#Note" ],
  "https://www.w3.org/ns/activitystreams#name" : [ {
    "@value" : "Another Simple Note"
  } ]
}, {
  "@id" : "_:genid-d893965296094717aa17b315578e9694-1BE77E66D0331B6E530E2856D60FA3CF",
  "@type" : [ "https://www.w3.org/ns/activitystreams#Note" ],
  "https://www.w3.org/ns/activitystreams#name" : [ {
    "@value" : "A Simple Note"
  } ]
}, {
  "@id" : "_:genid-d893965296094717aa17b315578e9694-FC2AD3A7C64C19128DED2CE7A7900840",
  "@type" : [ "https://www.w3.org/ns/activitystreams#OrderedCollection" ],
  "https://www.w3.org/ns/activitystreams#items" : [ {
    "@list" : [ {
      "@id" : "_:genid-d893965296094717aa17b315578e9694-1BE77E66D0331B6E530E2856D60FA3CF"
    }, {
      "@id" : "_:genid-d893965296094717aa17b315578e9694-0BEE8A4ED89FAB5FF8EB0ED84DC33231"
    } ]
  } ],
  "https://www.w3.org/ns/activitystreams#summary" : [ {
    "@value" : "Sally's notes"
  } ],
  "https://www.w3.org/ns/activitystreams#totalItems" : [ {
    "@type" : "http://www.w3.org/2001/XMLSchema#nonNegativeInteger",
    "@value" : "2"
  } ]
} ]

bart.h...@bosa.fgov.be

unread,
Mar 25, 2021, 10:42:23 AMMar 25
to RDF4J Users
Hi,

I feel your pain :-)

What you could do is transforming the JSON-LD file using JSON-LD Framing (https://www.w3.org/TR/json-ld11-framing/)
Basically using a kind of (JSON) template / config file to shorten the URIs, set defaults, and group nodes (or remove some nodes altogether).
It has some limitations, but it should at least make it less "scary" for non-linked-data devs...

A few years ago I made a quick'n'dirty example (https://github.com/Fedict/lod-frame).

Back in the days I had to apply a workaround when a JSON-LD file contained multiple graphs/contexts, 
but this issue could be fixed by now, haven't checked...


Best regards

Bart

rdf 4j

unread,
Mar 25, 2021, 12:58:15 PMMar 25
to rdf4j...@googlegroups.com
Aha, cool! Thanks!

i adjusted it to my needs, because i don't have files.

Without having any idea about framing, i thought that: 

`curl --location --request GET 'http://www.w3.org/ns/activitystreams' --header 'Accept: application/ld+json' `

looks so similar to your frame ;-) And just used it.
that's the result: (is it normal, that the whole framing is part of the result, even if it's not used? Or ist my downloaded frame not really a frame.)

```
{
"@context": {
"@vocab": "_:",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"as": "https://www.w3.org/ns/activitystreams#",
"ldp": "http://www.w3.org/ns/ldp#",
"vcard": "http://www.w3.org/2006/vcard/ns#",
"id": "@id",
"type": "@type",
"Accept": "as:Accept",
"Activity": "as:Activity",
"IntransitiveActivity": "as:IntransitiveActivity",
"Add": "as:Add",
"Announce": "as:Announce",
"Application": "as:Application",
"Arrive": "as:Arrive",
"Article": "as:Article",
"Audio": "as:Audio",
"Block": "as:Block",
"Collection": "as:Collection",
"CollectionPage": "as:CollectionPage",
"Relationship": "as:Relationship",
"Create": "as:Create",
"Delete": "as:Delete",
"Dislike": "as:Dislike",
"Document": "as:Document",
"Event": "as:Event",
"Follow": "as:Follow",
"Flag": "as:Flag",
"Group": "as:Group",
"Ignore": "as:Ignore",
"Image": "as:Image",
"Invite": "as:Invite",
"Join": "as:Join",
"Leave": "as:Leave",
"Like": "as:Like",
"Link": "as:Link",
"Mention": "as:Mention",
"Note": "as:Note",
"Object": "as:Object",
"Offer": "as:Offer",
"OrderedCollection": "as:OrderedCollection",
"OrderedCollectionPage": "as:OrderedCollectionPage",
"Organization": "as:Organization",
"Page": "as:Page",
"Person": "as:Person",
"Place": "as:Place",
"Profile": "as:Profile",
"Question": "as:Question",
"Reject": "as:Reject",
"Remove": "as:Remove",
"Service": "as:Service",
"TentativeAccept": "as:TentativeAccept",
"TentativeReject": "as:TentativeReject",
"Tombstone": "as:Tombstone",
"Undo": "as:Undo",
"Update": "as:Update",
"Video": "as:Video",
"View": "as:View",
"Listen": "as:Listen",
"Read": "as:Read",
"Move": "as:Move",
"Travel": "as:Travel",
"IsFollowing": "as:IsFollowing",
"IsFollowedBy": "as:IsFollowedBy",
"IsContact": "as:IsContact",
"IsMember": "as:IsMember",
"subject": {
"@id": "as:subject",
"@type": "@id"
},
"relationship": {
"@id": "as:relationship",
"@type": "@id"
},
"actor": {
"@id": "as:actor",
"@type": "@id"
},
"attributedTo": {
"@id": "as:attributedTo",
"@type": "@id"
},
"attachment": {
"@id": "as:attachment",
"@type": "@id"
},
"bcc": {
"@id": "as:bcc",
"@type": "@id"
},
"bto": {
"@id": "as:bto",
"@type": "@id"
},
"cc": {
"@id": "as:cc",
"@type": "@id"
},
"context": {
"@id": "as:context",
"@type": "@id"
},
"current": {
"@id": "as:current",
"@type": "@id"
},
"first": {
"@id": "as:first",
"@type": "@id"
},
"generator": {
"@id": "as:generator",
"@type": "@id"
},
"icon": {
"@id": "as:icon",
"@type": "@id"
},
"image": {
"@id": "as:image",
"@type": "@id"
},
"inReplyTo": {
"@id": "as:inReplyTo",
"@type": "@id"
},
"items": {
"@id": "as:items",
"@type": "@id"
},
"instrument": {
"@id": "as:instrument",
"@type": "@id"
},
"orderedItems": {
"@id": "as:items",
"@type": "@id",
"@container": "@list"
},
"last": {
"@id": "as:last",
"@type": "@id"
},
"location": {
"@id": "as:location",
"@type": "@id"
},
"next": {
"@id": "as:next",
"@type": "@id"
},
"object": {
"@id": "as:object",
"@type": "@id"
},
"oneOf": {
"@id": "as:oneOf",
"@type": "@id"
},
"anyOf": {
"@id": "as:anyOf",
"@type": "@id"
},
"closed": {
"@id": "as:closed",
"@type": "xsd:dateTime"
},
"origin": {
"@id": "as:origin",
"@type": "@id"
},
"accuracy": {
"@id": "as:accuracy",
"@type": "xsd:float"
},
"prev": {
"@id": "as:prev",
"@type": "@id"
},
"preview": {
"@id": "as:preview",
"@type": "@id"
},
"replies": {
"@id": "as:replies",
"@type": "@id"
},
"result": {
"@id": "as:result",
"@type": "@id"
},
"audience": {
"@id": "as:audience",
"@type": "@id"
},
"partOf": {
"@id": "as:partOf",
"@type": "@id"
},
"tag": {
"@id": "as:tag",
"@type": "@id"
},
"target": {
"@id": "as:target",
"@type": "@id"
},
"to": {
"@id": "as:to",
"@type": "@id"
},
"url": {
"@id": "as:url",
"@type": "@id"
},
"altitude": {
"@id": "as:altitude",
"@type": "xsd:float"
},
"content": "as:content",
"contentMap": {
"@id": "as:content",
"@container": "@language"
},
"name": "as:name",
"nameMap": {
"@id": "as:name",
"@container": "@language"
},
"duration": {
"@id": "as:duration",
"@type": "xsd:duration"
},
"endTime": {
"@id": "as:endTime",
"@type": "xsd:dateTime"
},
"height": {
"@id": "as:height",
"@type": "xsd:nonNegativeInteger"
},
"href": {
"@id": "as:href",
"@type": "@id"
},
"hreflang": "as:hreflang",
"latitude": {
"@id": "as:latitude",
"@type": "xsd:float"
},
"longitude": {
"@id": "as:longitude",
"@type": "xsd:float"
},
"mediaType": "as:mediaType",
"published": {
"@id": "as:published",
"@type": "xsd:dateTime"
},
"radius": {
"@id": "as:radius",
"@type": "xsd:float"
},
"rel": "as:rel",
"startIndex": {
"@id": "as:startIndex",
"@type": "xsd:nonNegativeInteger"
},
"startTime": {
"@id": "as:startTime",
"@type": "xsd:dateTime"
},
"summary": "as:summary",
"summaryMap": {
"@id": "as:summary",
"@container": "@language"
},
"totalItems": {
"@id": "as:totalItems",
"@type": "xsd:nonNegativeInteger"
},
"units": "as:units",
"updated": {
"@id": "as:updated",
"@type": "xsd:dateTime"
},
"width": {
"@id": "as:width",
"@type": "xsd:nonNegativeInteger"
},
"describes": {
"@id": "as:describes",
"@type": "@id"
},
"formerType": {
"@id": "as:formerType",
"@type": "@id"
},
"deleted": {
"@id": "as:deleted",
"@type": "xsd:dateTime"
},
"inbox": {
"@id": "ldp:inbox",
"@type": "@id"
},
"outbox": {
"@id": "as:outbox",
"@type": "@id"
},
"following": {
"@id": "as:following",
"@type": "@id"
},
"followers": {
"@id": "as:followers",
"@type": "@id"
},
"streams": {
"@id": "as:streams",
"@type": "@id"
},
"preferredUsername": "as:preferredUsername",
"endpoints": {
"@id": "as:endpoints",
"@type": "@id"
},
"uploadMedia": {
"@id": "as:uploadMedia",
"@type": "@id"
},
"proxyUrl": {
"@id": "as:proxyUrl",
"@type": "@id"
},
"liked": {
"@id": "as:liked",
"@type": "@id"
},
"oauthAuthorizationEndpoint": {
"@id": "as:oauthAuthorizationEndpoint",
"@type": "@id"
},
"oauthTokenEndpoint": {
"@id": "as:oauthTokenEndpoint",
"@type": "@id"
},
"provideClientKey": {
"@id": "as:provideClientKey",
"@type": "@id"
},
"signClientKey": {
"@id": "as:signClientKey",
"@type": "@id"
},
"sharedInbox": {
"@id": "as:sharedInbox",
"@type": "@id"
},
"Public": {
"@id": "as:Public",
"@type": "@id"
},
"source": "as:source",
"likes": {
"@id": "as:likes",
"@type": "@id"
},
"shares": {
"@id": "as:shares",
"@type": "@id"
},
"alsoKnownAs": {
"@id": "as:alsoKnownAs",
"@type": "@id"
}
},
"@graph": [
{
"id": "_:b0",

"type": "Note",
"name": "A Simple Note"
},
{
"type": "OrderedCollection",
"orderedItems": [
{
"id": "_:b0",
"type": "Note",
"name": "A Simple Note"
},
{
"id": "_:b2",

"type": "Note",
"name": "Another Simple Note"
}
],

"summary": "Sally's notes",
"totalItems": "2"
},
{
"id": "_:b2",

"type": "Note",
"name": "Another Simple Note"
}
]
}
```

--
You received this message because you are subscribed to the Google Groups "RDF4J Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdf4j-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rdf4j-users/639c8e96-9902-4d4d-aaf3-178a00edd093n%40googlegroups.com.

bart.h...@bosa.fgov.be

unread,
Mar 26, 2021, 10:15:16 AMMar 26
to RDF4J Users
Hi,

looks like the ActiveStreams editors indeed provided a convenient frame.

While the end result does not necessarily need the whole frame, it does need some context parts
(assuming the end result still needs to be JSON-LD, e.g. to turn the keys back into full IRIs when parsing the data)

One way to "hide" this is to just use a link to a (remote) context file
(though you may want to check if this always works for RDF4J, if memory serves me well, there is a ticket about setting/parsing the remote context)

Or to embed a custom context containing only the parts your application needs.
But this requires extra testing, and might be less future-proof / reusable (and/or confuse other linked data developers)

Or just shape the data using custom code to turn it into "plain" JSON
(which is again some extra work, especially if at some point in time the data needs to be converted back to JSON-LD...)

By the way, if you want to test framing or other JSON-LD features: the online JSON-LD Playground (json-ld.org) provides a lot of options.


Best regards

Bart
Reply all
Reply to author
Forward
0 new messages