Content-Type for JSON-LD Structured Data
Set the Content-Type header for JSON-LD (Linked Data) responses. Covers application/ld+json usage for SEO and API contexts.
Best Practices
Detailed Explanation
JSON-LD Content-Type
JSON-LD (JSON for Linked Data) uses the application/ld+json media type to signal that the content is JSON-LD structured data.
The Header Value
Content-Type: application/ld+json; charset=utf-8
What is JSON-LD?
JSON-LD is a method of encoding Linked Data using JSON. It is widely used for:
- SEO structured data (Schema.org markup)
- API responses with semantic annotations
- Knowledge graphs and linked open data
SEO Usage
Search engines like Google use JSON-LD to understand page content. In HTML, it is embedded in a <script> tag:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"headline": "How to Set Content-Type Headers",
"author": {
"@type": "Person",
"name": "Jane Developer"
}
}
</script>
API Usage
When serving JSON-LD from an API endpoint:
Content-Type: application/ld+json; charset=utf-8
The response body includes @context to define the vocabulary:
{
"@context": "https://schema.org",
"@type": "Product",
"name": "DevToolbox",
"description": "Developer tools portal"
}
Content Negotiation
Clients can request JSON-LD specifically:
Accept: application/ld+json
curl Example
curl -H "Accept: application/ld+json" \
https://api.example.com/products/1
Use Case
Use this when serving JSON-LD structured data from API endpoints, implementing content negotiation for linked data, or building semantic web applications.