I can easily conditionally set a field to null:
echo '{"id": 1, "more": "fields"}' \
| jq '{newId: (if .id == 1 then null else .id end), newMore: .more}'
yields
{
"newId": null,
"newMore": "fields"
}
But how can I conditionally delete it? I'm looking for something like:
echo '{"id": 1, "more": "fields"}' \
| jq '{
newId: (if .id == 1 then <special-value> else .id end),
newMore: .more
}'
to yield
{
"newMore": "fields"
}
Does such a <special-value> exist? If not, what are other viable solutions? They should ideally also be usable for large objects with many additional and nested fields.