【发布时间】:2017-10-25 23:27:34
【问题描述】:
我有以下数据集:
[
{
"py/object": "bit.ast.Node",
"_children": [
{
"py/object": "bit.ast.Node",
"_children": [
"main",
{
"py/object": "bit.ast.Node",
"_children": [
"args",
{
"py/object": "bit.ast.Node",
"_children": [
{
"py/object": "bit.ast.Node",
"_children": [
"str"
],
"source_column": 2,
"source_filename": "tests/fixture/hello.b",
"source_line": 1,
"tag": "type-named"
}
],
"base": {
"py/id": 10
},
"source_column": 2,
"source_filename": "tests/fixture/hello.b",
"source_line": 1,
"tag": "type",
"type": "array"
}
],
(等等……)
如何让jq 将_children 属性从所有拥有它的对象中排除?那么所有以_ 开头的属性呢?
以下似乎都不起作用:
jq 'map(del (._children))'
jq 'map(if has("_children") then del (._children) end)'
jq 'del(._children)'
jq 'del(.[]._children)'
jq 'del(.[]|._children)'
我不断收到类似于以下内容的错误:
jq: error (at <stdin>:1): Cannot index string with string "_children"
【问题讨论】:
-
请提供可用作输入的完整 JSON 样本。
-
@chepner 我所拥有的对于我的用例来说已经绰绰有余了。
-
@Qix - 没有看到更多的输入,很难查明您报告的错误的原因。