14

When I copy/paste JSON-LD example from Google Documentation (code-snippet below) I get an error in the Structured Data Testing Tool:

http://www.your-company-site.com (All values provided for http://www.example.com/ must have the same domain.)

Why is Google's own documentation example giving an error?

Code snippet from Google’s documentation:

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Organization",
  "url": "http://www.your-company-site.com",
  "contactPoint": [{
    "@type": "ContactPoint",
    "telephone": "+1-401-555-1212",
    "contactType": "customer service"
  }]
}
</script>
unor
  • 92,415
  • 26
  • 211
  • 360
Piece of Code
  • 141
  • 1
  • 6
  • 3
    It's weird, the code didn't throw error message one month ago. – rj487 Nov 01 '16 at 06:57
  • A single line of documentation would make the tester way more usable! – Michael Feb 13 '17 at 09:32
  • The answers and comments below seem to hold the correct info. Let's add an accepted answer and link all the other questions on this topic. – Michael Feb 13 '17 at 09:45
  • Another FYI: apparently this "error" only pops up for Organization types; I don't get this error for a Website entity – Michael Feb 13 '17 at 09:48

7 Answers7

10

It appears the testing tool assumes example.com as its domain.

When testing if you can update your url to "www.example.com" it will validate successfully.

<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "Organization",
  "url": "http://www.example.com/",
  "contactPoint": [{
    "@type": "ContactPoint",
    "telephone": "+1-401-555-1212",
    "contactType": "customer service"
  }]
}
</script>
sidarcy
  • 2,958
  • 2
  • 36
  • 37
5

This error started appearing somewhere in the month before your post. Since the error disappears when the "contactPoint" is left out, even though it doesn't contain an URL, this is most likely a bug in the validation tool.

I came across the same problem and asked about it on the support forum.

DieterDP
  • 4,039
  • 2
  • 29
  • 38
  • It appears that if you update the `@context` from `http://schema.org` to the same URL as your site, the 'all values provided' error goes away but causes a new "invalid type" error – Ben Parizek Nov 06 '16 at 07:25
  • 1
    @BenParizek: You shouldn’t do that, as you would no longer use the Schema.org vocabulary, but your own vocabulary instead. – unor Nov 06 '16 at 10:05
  • Changing @context to something else changes the meaning of the data. If you want to work with schema.org, you need to have that context (or fabricate one with the same definitions). Look up the JSON-LD spec if you want more details. – DieterDP Nov 06 '16 at 10:05
  • Understood. I wasn't proposing to do it as much as sharing a detail that seems to reveal which URL the error is trying to match when it fails validation in the testing tool right now. Worthwhile points to call out, however. – Ben Parizek Nov 06 '16 at 15:39
5

If you change your URL to "https://search.google.com/structured-data/testing-tool/", the tool will drop the error, just make sure before you put the code on your website that you update it.

Also, checking Search Console is likely a more reliable way (currently) to see if your markup has an error.

Bryan Heckler
  • 105
  • 4
  • 10
0

They can't prepopulate the examples in their documentation with the URL of the site you are going to write code for. They don't know what site you are writing code for.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Ok. But if I replace the snippet with my own data or other examples [Implementing JSON-LD](https://builtvisible.com/implementing-json-ld-wordpress/) I still get the same URL-error. – Piece of Code Oct 27 '16 at 09:10
  • Or does this only work on a live website? And how do I check that JSON-LD snippet? – Piece of Code Oct 27 '16 at 09:35
  • 1
    @PieceofCode — That testing tool, when you feed it copy/paste of the data instead of a URL, assumes the data is for `example.com`. You can either ignore errors about having the wrong hostname, change the data for the purposes of testing, or test in your live environment. – Quentin Oct 27 '16 at 09:49
  • Ok. Thanks for clearing that up. I was set on the wrong foot by validated screenshots in some blogposts but I assume those are from live/search console, not the testing-tool I referred to right? – Piece of Code Oct 27 '16 at 10:12
  • I voted your anwer up but because i'm new the vote is recorded and not displayed. – Piece of Code Oct 27 '16 at 10:13
  • @pieceofcode new users are restricted in voting answers up, it should show when your reputation is higher. Check SO's help section for more info. – Mousey Jan 01 '17 at 16:53
  • That's true but a) this is undocumented and b) only seems to be an issue for Organization entities; try it for a Website – Michael Feb 13 '17 at 09:50
0

If you are pasting some code on the page and running it, Google assumes that it should be an example page. Instead do like this,

  1. Test all other except "url"
  2. Update the index.html on your server
  3. Finally run test with your url (Choose New Test > Fetch URL)

Now you will not see the error again.

Ajay Singh
  • 692
  • 8
  • 19
0

I found that by implementing the JSON-LD snippet (with your correct details) in your website and clicking on 'New Test' at the top right of the Structured Data Test Page and using your correct URL it will not throw the error.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Jamie Lindsey
  • 928
  • 14
  • 26
0

One reason this happens is because of the testing tool's UX. It seems kinda buggy to me.

First run a fresh test on a domain. You will see the Organization url is correct and there are no warnings since all matches.

Now, click in the source code (left pane) and add a single space somewhere harmless. You will see the domain disappears in the top bar: enter image description here

You will also see the warning appear. Hitting "refresh" or starting a fresh test will correct the error again. I'm guessing the reason they do this is because when manually editing schema you are no longer, technically, reflecting the source from a domain.

dhaupin
  • 1,613
  • 2
  • 21
  • 24