What is the correct way to nest Schema.org Property Types inside an Object Type in JSON-LD - json

Question:
How to nest a Schema.org property types inside an Object Type in a JSON-LD code?
Context:
I have a website with pages about the biography of persons. I have a validated JSON-LD code for the Schema.org Person Object Type.
I want to expand the code to include the persons that came before and after a person in a certain role. For example, if the page is about a mayor of a city, I want to add the previous and following mayors.
The closest properties I could find are follows for the previous mayor (link) and followee (link) for the following mayor.
The Problem:
The property follows was validated with no problems, but followee gave an error if placed directly under the Person type as it requires a FollowAction type.
The property #followee is not recognized by Google for an object of type Person.
Workaround Tried:
I tried to nest the code, but I could not do this successfully.
For example:
<script type="application/ld+json">
{
"#context": "http://schema.org/",
"#type": "Person",
"name": "john Citizen",
{
"#context": "http://schema.org/",
"#type": "FollowAction",
"followee": {
"#type": "Person",
"name": "Steve"
}
}
}
</script>
I tired several other variations, but all led to errors. Are there any feasible correction to the code, or alternative ways to achieve the goal?

As I mentioned in the comment, I don't think follows or FollowAction are appropriate for your use.
For academic purposes, there is a way to mark up FollowAction inside a person. As FollowAction can reference a Person via it's agent, but not the other way around, you can use the reverse property to indicate a kind of backward reference:
<script type="application/ld+json">
{
"#context": "http://schema.org/",
"#type": "Person",
"name": "john Citizen",
"#reverse": {
"agent":
{
"#type": "FollowAction",
"followee": {
"#type": "Person",
"name": "Steve"
}
}
}
}
</script>

Related

What does mean #id and #type in json-ld context?

What does mean this statement in json-ld context?
{
"#context": {
"#version": 1.1,
"id": "#id",
"type": "#type"
}
}
and
{
"#context": {
"id": {"#type": "#id", "#id": "#id"},
"type": {"#type": "#id", "#id": "#type"}
}
}
I do not figure out that expression means what.
Json-Ld is designed to be interoperable with rdf. Therefore it introduces certain keywords marked with #. This keywords are needed to create rdf-statements from the json document.
A good starting point to get familar with the underlying concepts is to play around with the Json-Ld Playground. You will find some examples there. You can use the examples to create conversions from one format into another.
Getting rid of the '#'-character
Sometimes the '#'-character can become unhandy, e.g. when working with Javascript. In such situations it is possible to define an alias for an '#'-keyword. Like shown in your context:
{
"#context": {
"id": "#id",
"type": "#type"
}
}
By defining aliases for '#'-keywords the actual json document is easier to consume by non-rdf applications while it is still possible to process the data as rdf.

How to properly use mainEntityOfPage for a blog details page?

I've read several answers as to what mainEntityOfPage is and how to use it, and each one was more confusing than the last.
So my question is specific; I have a website which contains a blog section. On the blog details page I want to use structured data in JSON-LD format.
My question: would my mainEntityOfPage be WebPage or BlogPosting?
Should I use this:
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "WebPage",
"mainEntityOfPage": {
"#type": "BlogPosting",
}
}
</script>
or this:
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "BlogPosting",
"mainEntityOfPage": {
"#type": "WebPage",
}
}
</script>
I'm thinking the mainEntityOfPage is BlogPosting, so first example, yes? Or do I still have it all wrong?
The definition of mainEntityOfPage is:
Indicates a page (or other CreativeWork) for which this thing is the main entity being described.
The main entity on a blog post page is the blog post, not the page. So, the second snippet is correct:
{
"#context": "http://schema.org",
"#type": "BlogPosting",
"mainEntityOfPage": {
"#type": "WebPage"
}
}
If you want to use the first snippet (so that WebPage is the top-level item), you have to use mainEntity instead of mainEntityOfPage:
{
"#context": "http://schema.org",
"#type": "WebPage",
"mainEntity": {
"#type": "BlogPosting"
}
}
Note 1: mainEntity and mainEntityOfPage are inverse properties, so these two snippets mean the same.
Note 2: Maybe it helps to read it as "is the mainEntityOfPage", and "has mainEntity".
Note 3: You can use ItemPage (instead of WebPage) on the blog post pages.

Duplicate JSON-LD scripts in head

I have to inject multiple script elements for JSON-LD data into the head of my application, all pertaining to the same #type. This is due to pulling in different fields from different data source.
Will this duplication cause any problems?
<script type="application/ld+json">
{
"#type": "Organisation",
"name": "John Smith"
}
</script>
<script type="application/ld+json">
{
"#type": "Organisation",
"city": "London"
}
</script>
I'm hoping this will be translated by Google as simply:
<script type="application/ld+json">
{
"#type": "Organisation",
"name": "John Smith",
"city": "London"
}
</script>
Is that right?
Consumers can’t/shouldn’t assume that these JSON objects describe the same thing. (Think of a web page with information about many different organizations: it would of course be wrong to assume that they are the same organization.)
JSON-LD allows you to specify that the things described in different objects are identical: give them the same #id value.
#id takes an IRI which acts as identifier (it’s useful to provide them for many reasons).
See Node Identifiers in the JSON-LD spec.
So it could look like this (using Schema.org instead of your custom vocabulary):
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "Organization",
"#id": "/organizations/42#this",
"name": "ACME"
}
</script>
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "Organization",
"#id": "/organizations/42#this",
"description": "…"
}
</script>
(The relative URL /organizations/42#this would represent the organization itself. It’s best practice then to provide this JSON-LD as well your information about the organization under /organizations/42.)

Schema.org - JSON-LD For External Sites?

I have some Schema.org JSON-LD like:
<script type='application/ld+json'>
{
"#context": "http://www.schema.org",
"#type": "WebSite",
"name": "Name",
"alternateName": "Alt Name",
"url": "http://Website.com"
}
</script>
And i have a website with pages where i list other peoples websites with a URL and a bit of info text.
Could i add the Schema.org JSON-LD data for all the external websites? like:
"name": "External Website 001",
Or does does it have to be used only once for my own website details on the main page etc?
If you want to say something about another website, it’s perfectly fine to use the WebSite type. Schema.org types are not required to be exclusively about your own things.
Let’s say you are reviewing the other website. Then you could use something like:
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "Review",
"url": "/reviews/acme-website",
"itemReviewed":
{
"#type": "WebSite",
"name": "ACME",
"url": "http://acme.example.com/"
}
}
</script>
If it’s not a review, but an article about the site, you could use Article (instead of Review) and its about property (instead of itemReviewed).

How do I handle markup inside of a CreativeWork text property

I want to format a set of articles using schema.org, however the articles are not just text. They contain links, <em>s, <strong>s, and other light-weight markup. How do I put this in the text property correctly?
I considered just putting the markup in there, and that makes sense when it's inside of annotated HTML:
<div itemscope itemtype="http://schema.org/CreativeWork">
<h1 itemprop="name">An example I just wrote</h1>
<p itemprop="text">here's a link, it's very <em>important</em></p>
</div>
But if I were storing this as JSONLD, it would be rather strange to assume that text should be interpreted as HTML:
{
"#context": "http://schema.org",
"#type": "CreativeWork",
"name": "An example I just wrote"
"text": "here's a link, it's very <em>important</em>"
}
It's entirely possible that I could be writing with Markdown:
{
"#context": "http://schema.org",
"#type": "CreativeWork",
"name": "An example I just wrote"
"text": "here's a [link](http://example.com), it's very _important_"
}
Or any other language capable of expressing that same idea. And which language I'm using is rather important, because it indicates how the text should be read.
If you want to make it explicit what language you used, you can type the value. Taking your snippet above, it would look somewhat like this using the rdf:HTML datatype:
{
"#context": "http://schema.org",
"#type": "CreativeWork",
"name": "An example I just wrote"
"text": {
"#value": "here's a link, it's very <em>important</em>",
"#type": "http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML"
}
}