JSON-LD Frame:强制重复冗余属性值
JSON-LD Frame: Forcing duplication of redundant properties values
是否可以强制重复冗余属性值,例如author
和creator
?
目标是减少以后的额外解析并拥有一个易于行走的 JSON 对象,无论重复值如何。
样本:
{
"@type": "NewsArticle",
"articleBody": "Article Body",
"author": {
"id": "_:b1"
},
"creator": {
"id": "_:b1",
"type": "Person",
"name": "Creator Name",
"url": "https://example.org/author/creator-name/"
},
"description": "Description.",
"headline": "Headline"
}
框架:
{
"@context": "https://schema.org/docs/jsonldcontext.json",
"@vocab": "https://schema.org",
"@type": ["Article", "NewsArticle", "TechArticle", "ScholarlyArticle"],
"author": {
"@type": "http://schema.org/Person",
"@embed": "true"
}
}
预期结果:
{
"@type": "NewsArticle",
"articleBody": "Article Body",
"author": {
"id": "_:b1",
"type": "Person",
"name": "Creator Name",
"url": "https://example.org/author/creator-name/"
},
"creator": {
"id": "_:b1",
"type": "Person",
"name": "Creator Name",
"url": "https://example.org/author/creator-name/"
},
"description": "Description.",
"headline": "Headline"
}
要重复节点,您要使用 "@embed": "@always"
。试试 this update to your example on the JSON-LD Playground.
输入:
{
"@context": "https://schema.org/docs/jsonldcontext.json",
"@type": "NewsArticle",
"articleBody": "Article Body",
"author": {
"id": "_:b1"
},
"creator": {
"id": "_:b1",
"type": "Person",
"name": "Creator Name",
"url": "https://example.org/author/creator-name/"
},
"description": "Description.",
"headline": "Headline"
}
帧数:
{
"@context": "https://schema.org/docs/jsonldcontext.json",
"@type": ["Article", "NewsArticle", "TechArticle", "ScholarlyArticle"],
"author": {
"@embed": "@always"
},
"creator": {
"@embed": "@always"
}
}
结果:
{
"@context": "https://schema.org/docs/jsonldcontext.json",
"@graph": [
{
"type": "NewsArticle",
"articleBody": "Article Body",
"author": {
"id": "_:b1",
"type": "Person",
"name": "Creator Name",
"url": "https://example.org/author/creator-name/"
},
"creator": {
"id": "_:b1",
"type": "Person",
"name": "Creator Name",
"url": "https://example.org/author/creator-name/"
},
"description": "Description.",
"headline": "Headline"
}
]
}
是否可以强制重复冗余属性值,例如author
和creator
?
目标是减少以后的额外解析并拥有一个易于行走的 JSON 对象,无论重复值如何。
样本:
{
"@type": "NewsArticle",
"articleBody": "Article Body",
"author": {
"id": "_:b1"
},
"creator": {
"id": "_:b1",
"type": "Person",
"name": "Creator Name",
"url": "https://example.org/author/creator-name/"
},
"description": "Description.",
"headline": "Headline"
}
框架:
{
"@context": "https://schema.org/docs/jsonldcontext.json",
"@vocab": "https://schema.org",
"@type": ["Article", "NewsArticle", "TechArticle", "ScholarlyArticle"],
"author": {
"@type": "http://schema.org/Person",
"@embed": "true"
}
}
预期结果:
{
"@type": "NewsArticle",
"articleBody": "Article Body",
"author": {
"id": "_:b1",
"type": "Person",
"name": "Creator Name",
"url": "https://example.org/author/creator-name/"
},
"creator": {
"id": "_:b1",
"type": "Person",
"name": "Creator Name",
"url": "https://example.org/author/creator-name/"
},
"description": "Description.",
"headline": "Headline"
}
要重复节点,您要使用 "@embed": "@always"
。试试 this update to your example on the JSON-LD Playground.
输入:
{
"@context": "https://schema.org/docs/jsonldcontext.json",
"@type": "NewsArticle",
"articleBody": "Article Body",
"author": {
"id": "_:b1"
},
"creator": {
"id": "_:b1",
"type": "Person",
"name": "Creator Name",
"url": "https://example.org/author/creator-name/"
},
"description": "Description.",
"headline": "Headline"
}
帧数:
{
"@context": "https://schema.org/docs/jsonldcontext.json",
"@type": ["Article", "NewsArticle", "TechArticle", "ScholarlyArticle"],
"author": {
"@embed": "@always"
},
"creator": {
"@embed": "@always"
}
}
结果:
{
"@context": "https://schema.org/docs/jsonldcontext.json",
"@graph": [
{
"type": "NewsArticle",
"articleBody": "Article Body",
"author": {
"id": "_:b1",
"type": "Person",
"name": "Creator Name",
"url": "https://example.org/author/creator-name/"
},
"creator": {
"id": "_:b1",
"type": "Person",
"name": "Creator Name",
"url": "https://example.org/author/creator-name/"
},
"description": "Description.",
"headline": "Headline"
}
]
}