Re: Handling collections of items when single item in schema?

As long as you're declaring each instance of a schema.org/photo within the
scope of a schema.org/Place you're good-to-go.

In JSON-LD this is readily accomplished by using an array (JSON-LD example
1):

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Place",
  "name": "Venice Beach",
  "photo": [
    {
      "@type": "ImageObject",
      "url": "https://somedomain.com/veniceb1.jpg",
      "name": "Venice Beach by Day"
    },
    {
    "@type": "ImageObject",
    "url": "https://somedomain.com/veniceb2.jpg",
    "name": "Venice Beach by Night"
    } ]
}
</script>

Here's a simpler example using schema.org/image rather than schema.org/photo,
as image can use the expected type schema.org/URL (JSON-LD example 2):

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Place",
  "name": "Venice Beach",
  "image": [ "https://somedomain.com/veniceb1.jpg",
    "https://somedomain.com/veniceb2.jpg" ]
}
</script>

If using an inline syntax the code will be more verbose, but accomplish the
same thing.  Here's the equivalent of JSON-LD example 1 in microdata:

<div itemscope itemtype="https://schema.org/Place">
<h1 itemprop="name">Venice Beach</h1>
<p itemprop="photo" itemscope itemtype="https://schema.org/ImageObject">
<img src="https://somedomain.com/veniceb1.jpg" itemprop="url">
<span itemprop="name">Venice Beach by Day</span></p>
<p itemprop="photo" itemscope itemtype="https://schema.org/ImageObject">
<img src="https://somedomain.com/veniceb2.jpg" itemprop="url">
<span itemprop="name">Venice Beach by Night</span></p>
</div>

And the equivalent of JSON-LD example 2 in microdata:

<div itemscope itemtype="https://schema.org/Place">
<h1 itemprop="name">Venice Beach</h1>
<p><img src="https://somedomain.com/veniceb1.jpg" itemprop="image"></p>
<p><img src="https://somedomain.com/veniceb2.jpg" itemprop="image"></p>
</div>

If you run the examples through the Google Structured Data Testing Tool
<https://search.google.com/structured-data/testing-tool> you'll see that
the output of the first JSON-LD is exactly equivalent of that of the first
microdata example, and ditto for the second JSON-LD and microdata examples.

> My question is more general than this particular instance - I see a few
other situations where a schema specifies a single object as the Expected
Type, and I need to use a collection of objects.

If I'm interpreting your comment correctly, I think you may be
misunderstanding what "Expected Type" for a property signifies.  It is the
type, *or types*, expected as a value for that property.  "Type" here
either a basic schema.org/DataType, such a  number or text string, or some
other type of Thing in the vocabulary - e.g. schema.org/Organization, which
is the expected type for schema.org/department.

Where "a schema specifies a single object as the Expected Type" it is not
actually specifying a single *object*, but a single *expected type*.  E.g.
there is only one expected type for the property schema.org/illustrator,
and that is schema.org/Person.  That there is only one expected type
doesn't mean you are limited to providing a single value for this property,
but a value *or values* that are of the type Person.  I.e. you can specify
more than one Person for the illustrator property of Book.

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Book",
  "name": "My Big Book",
  "illustrator": [
    {
      "@type": "Person",
      "name": "Mary Doe"
    },
    {
    "@type": "Person",
    "name": "John Doe"
    } ]
}
</script>

When a property has more than one expected type it doesn't mean you then
can provide more values for that property, just that the value or values
you do provide are each expected to be of one of those types.  E.g. the
property schema.org/author expects the types schema.org/Person *or*
schema.org/Organization:  this doesn't mean that you "may now provide two
objects for author", but that "objects" (i.e. property values) you do
provide should be of one of these types.  You can say a book has one author
or 100:  the "Expected Type" field in the property table simply states what
*type* of Thing you should provide as an author.


On Wed, Jun 20, 2018 at 4:36 PM, Kevin Brown <kevinbrown2354@gmail.com>
wrote:

> I am writing a job board, and trying to use schema.org schemas in my data
> model. I notice for Place that I have the property "photo", which
> supersedes "photos" in the schema. How should I handle having multiple
> photos for a Place? My question is more general than this particular
> instance - I see a few other situations where a schema specifies a single
> object as the Expected Type, and I need to use a collection of objects.
>
> Thank you.
>

Received on Thursday, 21 June 2018 23:58:19 UTC