Assuming there is a json file:
{
"columns": {
"id": {
"required": true,
"type": "integer"
},
"name": {
"required": false,
"type": "string"
},
"description": {
"type": "string"
}
}
}
I want to use jq to get the value "required" field for each column. If the field "required" does not exist, it should return the default value false.
Specifically:
jq '.columns.id | getOrDefault("required", false)' # true
jq '.columns.name | getOrDefault("required", false)' # false
jq '.columns.description | getOrDefault("required", false)' # false
How to implement this magic getOrDefault() function in jq?