torann / json-ld Goto Github PK
View Code? Open in Web Editor NEWExtremely simple JSON-LD generator.
License: BSD 2-Clause "Simplified" License
Extremely simple JSON-LD generator.
License: BSD 2-Clause "Simplified" License
Hi
(you generator is very usefull, thanks)
I would like to know your opinion about the following use case:
As end user, I have html special char (like '<') into LD-JSON attributes
I write a little php script to represent the case:
<?php
require_once `vendor/autoload.php';
$context = \JsonLd\Context::create('news_article', [
'headline' => 'Article headline',
'description' => 'A terrible </script> here'
]);
echo $context;
echo "\n\nAn other way :\n\n";
$context = \JsonLd\Context::create('news_article', [
'headline' => 'Article headline',
'description' => htmlspecialchars('A terrible </script> here')
]);
echo $context;
Script output the following:
<script type="application/ld+json">{"@context":"http:\/\/schema.org","@type":"NewsArticle","headline":"Article headline","description":"A terrible <\/script> here"}</script>
An other way :
<script type="application/ld+json">{"@context":"http:\/\/schema.org","@type":"NewsArticle","headline":"Article headline","description":"A terrible <\/script> here"}</script>
You should notice that the first sample output an invalid HTML
I had created dedicated html page to show the escape issue:
https://gist.github.com/boly38/77164ae66055b596d75f62d789a4266a
I'm asking myself about where htmlspecialchars
should be ?
what do you think?
As end-user, would be great that the library manages that point for me as, per specification, toString result is ready to embed html script.
thanks
Hello Torann, I'm getting "Could not find package torann/json-ld at any version matching your PHP version 5.4.45.0" while trying to install your library. Even with --ignore-platform-reqs it's not working. Any ideas?
Hi
Using LD-JSON, it should be possible to define multiple times the same entity type on a given things.
For example, an Article could includes multiples "comments".
(need to confirm that point)
So out of error from me, mean that in this use case, 'comment' will be an array of objects ("Comment" type) and not a single entity. I think the library doens't allow us to do that?
I saw "breadcrumb" sample, but that seems to be a specific list example.
And as today, "field name" is used to work with ContextTypes attributes, so it will not be easy to implement?
Maybe should we use/implement @graph
(src )?
The question is:
AggregateRating
should contain itemReviewed
property.
https://schema.org/AggregateRating
Not sure, but it looks like property was removed at release >= 0.0.11
<script type="application/ld+json">{"@context":"http:\/\/schema.org","@type":"AggregateRating","sameAs":"https:\/\/example.com/item","reviewCount":"129","ratingValue":"3.40","bestRating":5,"worstRating":1,"ratingCount":"129"}</script>
This is example context generated with current property-set for AggregateRating
You can check it at Google Schema Validator https://search.google.com/structured-data/testing-tool
Check result: 1 error - The review has no reviewed item specified.
Is PHP v5.5.9
actually not supported ?
Is there TravisCI builds history available for checking ?
Thanks in advance,
Add headline to Article class as a structure property
Please. fix it.
Hello
What is the correct way to display bussines including Review?
We have to modifiy this line:
$properties = array_filter($properties, 'strlen');
Because this line removes all arrays from product, which es added bei isSimilarTo property. For example: it removes "offers" , which is required for valid structured data.
Fix could be:
$properties= array_filter($properties, function($var) {
return !empty($var);
});
It leads you to a 404 page.
I need support for at least the @language to specify the language as seen in https://www.w3.org/TR/json-ld/#h3_syntax-tokens-and-keywords
Any plans to for that?
Hi there and thanks for your nice work!
I'm missing a few important properties in LocalBusiness like:
and a few more.
Is there a way to extend this?
I'd like to add support for schemas definied in health-lifesci
e.g. http://health-lifesci.schema.org/MedicalWebPage
Hi
Thanks for providing this library.
Would it be possible to support the new VirtualLocation feature?
https://developers.google.com/search/docs/data-types/event#virtual-location (Make sure the page is displayed in english).
Or is this already possible via custom code? We're using the 'location' array key and the library automatically creates the '@place' property.
Hi,
Many thanks. We're happy with your library.
I noticed that for the type "event", both "image" and "description" is not supported.
Is that on purpose or can I add them somehow myself?
As object, please add a way to print only the json ld without the wrapping tag
Hi
I have a little problem when I have to add a list of reviews in the schema article it accepts just one review
'review' => Review::class
I created a new ContextType file called LodgingBusiness
. It looks like this:
<?php
namespace JsonLd\ContextTypes;
class LodgingBusiness extends LocalBusiness
{
/**
* Property structure
*
* @var array
*/
protected $structure = [
'@id' => null,
'starRating' => null,
'petsAllowed' => null,
];
}
I'm trying to use it like this:
$context = \JsonLd\Context::create('lodging_business', [
'name' => $this->row->title,
]);
but i cant get any output. What am i doing wrong?
Since PHP support for 5.6 has stopped long ago and even version 7.1 only has security support (until December 1st), I would like to propose to set the required PHP version to >=7.2. This would, allow for some clean up of code, enable more type hinting, etc.
Please let me know if other people would like move forward too or if there are any reasons why not to do this.
Does this plugin support ItemList
?
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.
\JsonLd\Context::create(Foo, $data)
inside the main arraynew \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…
Let me start, by thank you for the awesome simple code you've been maintaining @Torann.
More of a question, rather than an issue :
Our system needs to create a schema, connecting a product, with it's three most popular. Thus:
https://schema.org/Product -> https://schema.org/isSimilarTo -> Many https://schema.org/Product
For one product, no problem, we're awesome.
What about when we want to connect it to many other contexts products?
How might we go on to implement that feature? Is this the way to go? https://github.com/Torann/json-ld/pull/20/files
Thank you in advance
I'm trying to publish an article with multiple authors but all I get is the following without any author data.
"author": {
"@type": "Author"
},
Is there a way to create an array like the following answer so it looks like the json below:
https://webmasters.stackexchange.com/a/90191
"author": [{
"@type": "Person",
"familyName": "van der Westhuizon",
"givenName": "Jason",
"name": "Jason van der Westhuizon"
},
{
"@type": "Person",
"familyName": "du Toit",
"givenName": "Jene",
"name": "Jene du Toit"
}]
Thank you!
Ive noticed that if you chose Blog Post as the type - it doesnt display the 'headline' - even if its passed into the create method...i.e:
$JSONsructuredData = \JsonLd\Context::create('blog_posting', [
'name' => $post->title,
'headline' => $post->title,
'datePublished' => $post->publish_date->format('Y-m-d').'T'.$post->publish_date->format('H:m:s'),
'dateModified' => $post->publish_date->format('Y-m-d').'T'.$post->publish_date->format('H:m:s'),
'image' => [
'type' => 'ImageObject',
'url' => env('APP_URL').$post->feature_image,
'width' => '850',
'height' => '350'
],
'publisher' => [
'type' => 'Organization',
'name' => 'SomeBlogSite',
'logo' => [
'type' => 'ImageObject',
'url' => env('APP_URL').'img/logo/imge.png',
'width' => '600',
'height' => '150'
],
],
'mainEntityOfPage' => [
'type' => 'WebPage',
'id' => env('APP_URL').'lobby/'.$post_slug,
],
'author' => [
'type' => 'Person',
'name' => $post->user->name,
],
]);
It just ignores the ''headline' => $post->title,' - although I can see in the $structure of the CreativeWork Class it had 'headline' => null' ...but would appear it never actually sets it for display, even when passing in the value???
Cheers
The NewsArticle Class, is missing the articleBody property.
Using it doesn't work.
See the specification here: http://jsonld.com/news-article/
I'm trying to do sameAs as simple array, but mapProperty support only structured data
AggregateOffer (https://schema.org/AggregateOffer) isn't supported and result in a normal Offer. Could this be added?
return Context::create('product', [
'name' => 'some name',
'image' => [
'https://site.com/image1.png',
'https://site.com/image2.png'
],
'description' => 'some description',
'brand' => [
'@type' => 'Brand',
'name' => 'Awesome brand'
],
'offers' => [
'@type' => 'AggregateOffer',
'offerCount' => 3,
'lowPrice' => 100,
'highPrice' => 200,
'priceCurrency' => 'EUR'
]
]);
Expected:
{"@context":"http:\/\/schema.org","@type":"Product","name":"some name","description":"some description","brand":{"@type":"Brand","name":"Awesome brand"},"image":["https:\/\/site.com\/image1.png","https:\/\/site.com\/image2.png"],
"offers":{
"@type":"AggregateOffer",
"offerCount": "3",
"lowPrice": "100",
"highPrice": "200",
"priceCurrency":"EUR"
}
}
Actual:
{"@context":"http:\/\/schema.org","@type":"Product","name":"some name","description":"some description","brand":{"@type":"Brand","name":"Awesome brand"},"image":["https:\/\/site.com\/image1.png","https:\/\/site.com\/image2.png"],
"offers":{
"@type":"Offer",
"priceCurrency":"EUR"
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.