Any better suggestions for how to transform an empty result to `0`

I tried ` | sed 's/^$/0/'` but it did not work, and I couldn't figure out how to fix that.