json-ld icon indicating copy to clipboard operation
json-ld copied to clipboard

Nesting (e.g. Review inside Book, ratings inside reviews etc.)

Open wturrell opened this issue 3 years ago • 0 comments

Is passing one jsonld ContextType into another officially supported? I assumed it would be, but none of the examples show it and I'm having loads of problems.

I've tried a couple of ways - e.g.

  • just nesting another call to \JsonLd\Context::create(Foo, $data) inside the main array
  • creating an entirely new instance with new \JsonLd\ContextTypes\Person()

Typically, the end output will either have an empty array where the nested context should be, or what looks like raw object data: i.e. only the @type defined and a "properties" array of everything, regardless of whether a value has been supplied - so mostly a long, empty list.

I've also come across situations where the second object works, but it fails on adding a third level (you may need to nest a Person (the reviewer) inside a Review inside a Book, for example).

Thanks in advance…

wturrell avatar May 03 '21 17:05 wturrell