HN2new | past | comments | ask | show | jobs | submitlogin

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.




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

Search: