Today I Learned

hashrocket A Hashrocket project

Json default value using jq

Today I learned that we can specify a default value when getting a node in json using jq:

{
  "users": [
    {"name": "John"},
    {}
  ]
}
cat my.json | jq '[.users[] | .name // "my-default"]'
# [
#   "John",
#   "my-default"
# ]
See More #command-line TILs