【发布时间】:2023-02-17 07:40:48
【问题描述】:
我有一个 json 架构,用于标记需要处理的特殊属性,我想通过 JsonPath.Evaluate 查询这些属性。
这是说明问题的架构的一部分
{
"type": "object",
"properties": {
"period": {
"description": "The period in which the rule applies",
"type": "object",
"properties": {
"start": {
"type": "string",
"format": "date-time"
},
"end": {
"type": "string",
"format": "date-time"
}
},
"required": [
"start"
],
"x-updateIndicatorProperties": [
"start"
]
},
"productType": {
"type": "string"
},
"x-updateIndicatorProperties": [
"productType"
]
}
}
我想获取“x-updateIndicatorProperties”属性的 JsonPath,以便我可以查询要处理的实际属性。 对于这个例子,预期的结果是
[
"$['properties']['x-updateIndicatorProperties']",
"$['properties']['period']['x-updateIndicatorProperties']"
]
我一直在尝试获取一个 JsonPath 表达式来查询这些属性。 目前我只是迭代所有属性并手动过滤它们: “$..*”
我也试过使用: $..['x-updateIndicatorProperties']
这行得通。但它返回了很多重复项。对于上面的例子,我得到了 5 个结果而不是预期的 2 个。可以在这里演示:https://json-everything.net/json-path
假设我不能影响架构本身,只能影响遍历它的代码, 任何人都可以帮助表达以获得预期的结果或任何其他方式来实现相同的结果吗?
堆栈是 JsonPath 0.2.0、.net 6 和 system.text.json。
【问题讨论】:
-
我希望递归体面的路径(你发布的
$..[])应该有效。不知道为什么它返回重复项。这似乎是一个错误。你能在我的 GitHub 回购上打开一个问题吗?
标签: jsonpath c#-6.0 system.text.json json-everything