Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning empty to multiple paths #2440

Closed
johannes-riecken opened this issue Jun 9, 2022 · 1 comment · Fixed by #2133
Closed

Assigning empty to multiple paths #2440

johannes-riecken opened this issue Jun 9, 2022 · 1 comment · Fixed by #2133

Comments

@johannes-riecken
Copy link

Describe the bug

In (.[].children|.[])|=if has("color") then . else empty end, empty behaves different from regular values.

To Reproduce

Run jq '(.[].children|.[])|=if has("color") then . else empty end' foo.json, where foo.json is:

[
    {
        "name": "foo",
        "children": [{
            "name": "foo.0",
            "color": "red"
        }]
    },
    {
        "name": "bar",
        "children": [{
            "name": "bar.0",
            "color": "green"
        },
        {
            "name": "bar.1"
        }]
    },
    {
        "name": "baz",
        "children": [{
            "name": "baz.0"
        },
        {
            "name": "baz.1"
        }]
    }
]

Output:

[
  {
    "name": "foo",
    "children": [
      {
        "name": "foo.0",
        "color": "red"
      }
    ]
  },
  {
    "name": "bar",
    "children": [
      {
        "name": "bar.0",
        "color": "green"
      }
    ]
  },
  {
    "name": "baz",
    "children": [
      {
        "name": "baz.1"
      }
    ]
  }
]

Expected behavior

I expected this output, which I can get by running del(.[].children[] | select(has("color") | not)).

[
  {
    "name": "foo",
    "children": [
      {
        "name": "foo.0",
        "color": "red"
      }
    ]
  },
  {
    "name": "bar",
    "children": [
      {
        "name": "bar.0",
        "color": "green"
      }
    ]
  },
  {
    "name": "baz",
    "children": []
  }
]

Environment (please complete the following information):

  • OS and Version: macOS Monterey (M1 architecture)
  • jq version 1.6
@itchyny
Copy link
Contributor

itchyny commented Jun 13, 2022

This is duplicate of #2051.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants