Duplicate JSON-LD scripts in head - html

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.)

Related

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

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>

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.

JSON-LD format for WebPage and BlogPosting

I have a medic weblog. My first page only has some data and top posts.
So I use this:
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "WebPage",
"name": "website name",
"description": "website description",
"publisher": {
"#type": "WebPageMedic",
"name": "my company name"
}
}
</script>
Now for another page, how can I write JSON-LD format?
I try this:
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "WebPage",
"name": "website name",
"description": "website description",
"publisher": {
"#type": "WebPageMedic",
"name": "my company name"
},
"mainEntity":{
"#type":"BlogPosting",
"headline":"BlogPosting",
"datePublished":"2015-03-09T13:08:00-07:00",
"articleBody": "articleBody"
}
}
</script>
I think I must write website information (WebPage) in all pages and then in mainEntity I can write BlogPosting and other things.
Am I right?
Yes, that is an appropriate structure if you want to have a WebPage item for every page (which is not necessary, but can be useful).
For a page that has multiple blog posts (in which case you might want to use CollectionPage), you could use a Blog item or an ItemList item as main entity. Another option is to use the hasPart property. See an example with mainEntity ItemList.
Notes about your example:
The properties of WebPage should be about the page, not about the site. You used "website name" and "website description". If you want to state something about your site, you can use the WebSite type.
There is no WebPageMedic type. You’ll probably want to use Organization or one of its sub-types, e.g., MedicalBusiness.

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).

There is any way to reuse data on json-ld?

There is some way to reuse data in json-ld?
I have a WebSite and an Organization schemas with name, url and social links on it, i'm trying to get a better Google SEO and maybe one Google Graph Card like this:
https://developers.google.com/search/docs/guides/enhance-site
My json-ld is something like this:
<script type="application/ld+json">
[
{
"#context": "http://schema.org",
"#type": "WebSite",
"name": "Name",
"url": "http://www.example.com"
},
{
"#context": "http://schema.org",
"#type": "Organization",
"name": "Name",
"url": "http://www.example.com",
"sameAs": [
"https://twitter.com/example"
]
}
]
</script>
There is some way to not repeat name and url in both schemas?
And am I doing right? i really need the Organization schema to get these social links on the google card? Or the "sameAs" key could be in the WebSite schema?
I am following this guides:
https://developers.google.com/search/docs/data-types/sitename
https://developers.google.com/search/docs/data-types/social-profile-links