如何在JSON-LD框架中匹配不存在的属性而不输出默认值



我有一个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值的属性。

最新更新