Giter VIP home page Giter VIP logo

Comments (5)

emanuele6 avatar emanuele6 commented on June 30, 2024 1

Nevermind, I can reproduce it now, I was using the wrong binary; sorry! ^^
Anyway, I think this was only not erroring because try was bugged in many ways in jq 1.6. Especially when used in combination with foreach which was very annoying. :-(
If you try null | ascii_downcase even in jq 1.6 it will error. And in that command, it is supposed to error.

I am not sure I understand what the intent of that jq command is supposed to be.
If you want to only keep the objects that either don't contain .baz or that have a .baz equal to null or "", I suggest using this instead:

jq 'del(.[] | select(.baz | IN(null, "") | not))'
# alternatively
jq 'del(.[] | select((.baz // "") != ""))'
jq 'map(select(.baz | IN(null, "")))'
jq 'map(select((.baz // "") == ""))'

If you want to only remove objects that contain a "baz" in general, you can use:

jq 'del(.[] | select(has("baz")))'
# or, if you want to also keep objects with {"baz":null}
jq 'del(.[] | select(.baz != null))'

from jq.

emanuele6 avatar emanuele6 commented on June 30, 2024

@gursewak1997
I cannot reproduce that command not failing in jq 1.6.
The exception is triggered by {"foo":"bar"} | .baz returning null succesfully (since there is not a "baz" key in the object), and then null | ascii_downcase being called, and ascii_downcase is not in a try block.
ascii_downcase errors for non-string inputs in both jq 1.6, jq 1.7, and jq 1.7.1.
{"foo":"bar"} | .baz retruns null in both jq 1.6, jq 1.7, and jq 1.7.1. .baz would only error if the input is neither null nor an object. If the specified key is missing from the input object, or if the input is null, it just returns null in all versions of jq, it does not error.

from jq.

emanuele6 avatar emanuele6 commented on June 30, 2024

I don't get what is the point of using ascii_downcase == "" either.

from jq.

itchyny avatar itchyny commented on June 30, 2024

See #1859, #2750. This is working as intended in 1.7. In 1.6 try catches the error of ascii_downcase but it should not.

from jq.

jlebon avatar jlebon commented on June 30, 2024

@emanuele6 For posterity, note the example here is just a minimal reproducer. The real world use case it was boiled down from can be seen in coreos/fedora-coreos-config#2797 (where we worked around it).

from jq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.