Best JSON-LD practices: using multiple elements?

There is no benefit in having single or multiple data blocks, other than limitations around how you might store and manage schema data in your website. For example, you might need them separate if different components within your website are responsible for generating each data block independently. Alternatively, if your website is able to manage … Read more

How to convert RDF to pretty nested JSON using java rdf4j

Use framing import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.StringWriter; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.rio.RDFFormat; import org.eclipse.rdf4j.rio.RDFHandlerException; import org.eclipse.rdf4j.rio.RDFParser; import org.eclipse.rdf4j.rio.RDFWriter; import org.eclipse.rdf4j.rio.Rio; import org.eclipse.rdf4j.rio.helpers.StatementCollector; import org.junit.Test; import com.github.jsonldjava.core.JsonLdOptions; import com.github.jsonldjava.core.JsonLdProcessor; import com.github.jsonldjava.utils.JsonUtils; import com.google.common.base.Charsets; public class HowToConvertRdfToJson { @Test public void convertRdfToPrettyJson(){ try(InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(“book.ttl”)){ System.out.println(getPrettyJsonLdString(in,RDFFormat.TURTLE)); }catch(Exception e){ … Read more

Schema.org – JSON-LD – Where to Place?

The data can be placed anywhere. From Google’s documentation: The data, enclosed within the <script type=”application/ld+json”> … </script> tags as shown in the examples below, may be placed in either the <HEAD> or <BODY> region of the page that displays that event. You can also use data dynamically fetched using AJAX: JSON-LD markup inserted by … Read more

Adding script tags in Angular component template

Maybe a little late to the party here, but since the above answers do not work well with Angular SSR (e.g. document is not defined server-side or document.createElement is not a function), I decided to write a version that works for Angular 4+, in both server and browser context: Component Implementation import { Renderer2, OnInit, … Read more

Schema.org JSON-LD reference

You can identify a node by giving it a URI, specified in the @id keyword. This URI can be used to reference that node. See the section “Node Identifiers” in the JSON-LD spec. So your main event could get the URI http://example.com/2016-04-21#main-event: <script type=”application/ld+json”> { “@id”: “http://example.com/2016-04-21#main-event”, “@context”: “http://schema.org”, “@type”: “Event”, “name”: “MainEvent”, “startDate”: “2016-04-21T12:00” … Read more

JSON-LD Schema.org: Multiple video/image page

If you have multiple items as value of a property, you could use an array: <script type=”application/ld+json”> { “@context”: “http://schema.org”, “@type”: “WebPage”, “video”: [ { “@type”: “VideoObject” }, { “@type”: “VideoObject” } ] } </script> If you have multiple items on the top-level (not as value of a property), you could use a (named) graph … Read more