如何在JSON中实现h-product微格式?是否采用JSON+LD?
Great question! Let’s break this down clearly:
You don’t have to use JSON-LD to represent h-product in JSON. Microformats-2 has its own standardized JSON serialization called mf2 JSON, which is the official way to encode microformats data in JSON. That said, JSON-LD is a valid alternative if you’re targeting systems that prefer linked data formats (like most major search engines), but it’s not a requirement for microformats compliance.
1. h-product in mf2 JSON (Microformats' native JSON format)
This is the go-to if you want to stick strictly to microformats-2 specs. Here’s a complete, valid example:
{ "type": ["h-product"], "properties": { "name": ["Acme Wireless Headphones"], "description": ["Noise-canceling over-ear headphones with 30-hour battery life"], "photo": ["https://example.com/headphones.jpg"], "brand": [{ "type": ["h-card"], "properties": { "name": ["Acme Electronics"], "url": ["https://example.com/acme"] } }], "price": ["$199.99"], "priceCurrency": ["USD"], "sku": ["AWH-001"], "url": ["https://example.com/products/awh-001"] } }
Quick tips for mf2 JSON:
- The root object always has a
typearray listing the microformat(s) (here justh-product). - All attributes live under
properties, and values are arrays—even for single values, since microformats allow multiple instances of some properties (like multiple photos). - Nested microformats (like
h-cardfor the brand) follow the sametype+propertiesstructure.
2. h-product in JSON-LD (Alternative linked data format)
If your main goal is to get your product data recognized by search engines or tools that use Schema.org, JSON-LD is a solid choice. You’ll map h-product properties to Schema.org’s Product type, like this:
{ "@context": "https://schema.org", "@type": "Product", "name": "Acme Wireless Headphones", "description": "Noise-canceling over-ear headphones with 30-hour battery life", "image": "https://example.com/headphones.jpg", "brand": { "@type": "Brand", "name": "Acme Electronics", "url": "https://example.com/acme" }, "offers": { "@type": "Offer", "price": "199.99", "priceCurrency": "USD" }, "sku": "AWH-001", "url": "https://example.com/products/awh-001" }
Key differences from mf2:
- Uses Schema.org’s vocabulary instead of microformats-2’s, so the structure is a bit different (e.g., price info lives inside an
offersobject instead of being top-level). - Requires
@contextand@typeto define the linked data context.
Which should you pick?
- Go with mf2 JSON if you’re working in the microformats/indieweb space, or need compatibility with tools that parse microformats specifically.
- Use JSON-LD if you’re optimizing for search engines or systems that rely on Schema.org.
- Feel free to use both! Many sites include microformats in their HTML and JSON-LD in
<script>tags to cover all bases.
内容的提问来源于stack exchange,提问作者Scarletngold

