我不理解,为什么在过滤所有物体和阵列的物品时,无效价值也受到影响。
我迄今没有找到任何工作。
投入:
$ cat test.json
{
"object": {
"key1": 1,
"key2": null,
"key3": 3
},
"array": [ "a", null, "c" ]
}
实际行为,意想不到的无效价值产出:
$ jq [ paths(select(type | IN("object", "array") | not)) as $path | { "($path)": getpath($path) } ] | add test.json
{
"["object","key1"]": 1,
"["object","key3"]": 3,
"["array",0]": "a",
"["array",2]": "c"
}
预期(和预期)产出:
{
"["object","key1"]": 1,
"["object","key2"]": null,
"["object","key3"]": 3,
"["array",0]": "a",
"["array",1]": null,
"["array",2]": "c"
}
EDIT:
我们可以在这里看到,如果不采用过滤器,那么具有无效价值的道路就是产出:
$ jq [ paths as $path | { "($path)": getpath($path) } ] | add test.json
{
"["object"]": {
"key1": 1,
"key2": null,
"key3": 3
},
"["object","key1"]": 1,
"["object","key2"]": null,
"["object","key3"]": 3,
"["array"]": [
"a",
null,
"c"
],
"["array",0]": "a",
"["array",1]": null,
"["array",2]": "c"
}