You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在JSON中实现h-product微格式?是否采用JSON+LD?

h-product in JSON: mf2 vs 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 type array listing the microformat(s) (here just h-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-card for the brand) follow the same type + properties structure.

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 offers object instead of being top-level).
  • Requires @context and @type to 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:37:54