我有一个schema:ProductGroup和schema:PoductModel节点的图,我已经编写了一个框架,以嵌套结构输出它,概念上类似于图书馆书籍章节的示例。一切都正常,只是框架输出在顶级ProductGroup
上包含一个isVariantOf: null
,我不希望它。
{
"@context": {
"@vocab": "http://schema.org/",
"ex": "http://example.com/"
},
"@id": "ex:100",
"@type": "ProductGroup",
"hasVariant": [...],
"isVariantOf": null,
"name": "All The Things"
}
JSON-LD Playground中的完整示例(在Flattened和Framed之间切换以使其正确输出(。
顶级ProductGroup
没有isVariantOf
属性。在我的框架文档中,我匹配的是空的。但是,我不知道如何在输出中省略空的isVariantOf
属性。我想我必须设置@omitDefault
标志,但我很难弄清楚在哪里或如何设置。
{
"@context": {
"@vocab": "http://schema.org/",
"ex": "http://example.com/"
},
"@graph": {
"@type": "ProductGroup",
"@requireAll": true,
"isVariantOf": []
}
}
如《框架规范》中所述,使用Match on the Leasing of a Property机制将带有null
的属性显式添加到输出中,以指示该属性不存在。要删除它,您可以使用框架作为上下文来重新压缩结果,因为扩展算法会删除所有具有null值的属性。