Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You should be able to do some pipe fu and carry out some form of merging via bash. I mostly use it for making our output more readable or producing CSV style reports with the filtered data. Its filters are probably the biggest feature, at least in my mind.


Sorry for not being clear. I meant a merge in the form of {"a": 1, "b": 2, "c": 3} merged with {"b": 20} returning {"a": 1, "b": 20, "c": 3}. Like Python's update() or PHP's array_replace_recursive() although PHP's a little richer.


    jq 'reduce .[] as $obj ({}; .+$obj)'
or

    jq -s 'reduce .[] as $obj ({}; .+$obj)'
should do it. `+` adds objects by merging them.


Thanks! I'm eager to try this and hopefully clean up my code!


If you can code it using jq itself, you can submit a pull request and have it added to the builtins.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: