I know a lot of people on HN are not a fan of monetising with ads.
That said, an alternative to writing a whole book before seeing if people will pay, is to write a blog.
You’ll get validation in smaller chunks and can iterate.
Currently the display ads on my blog pay between $15 - $30 per thousand visitors, and many blogs earn a lot more than that.
If you’re writing a non fiction book in a technical niche, it’s fairly easy to get traffic from Google if you write in depth posts around 1,500 words each.