79777896

Date: 2025-09-29 08:44:19
Score: 1.5
Natty:
Report link

I want to add another answer to this old question, because I prefer the use of basic tools (available on most systems) and I’d like to clarify why the trivial approach doesn’t work.


Why trivial approach will not work?

cat sample.json |  jq '.Actions[] | select (.properties.age == "3") .properties.other = "no-test"' >sample.json

At first glance this looks fine but it does not work. First of all, problem with overriding file comes from >sample.json not the jq itselft. When you use >sample.json, the shell immediately opens the file for writing before jq starts reading it, which truncates the file to zero length.


How to work around it? Simply use a command that handle output itself (like sed -i wget -O etc. ) not via shell redirections.

cat sample.json |  jq '.Actions[] | select (.properties.age == "3") .properties.other = "no-test"' | dd of=sample.json status=none
Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Konrad Ziarko