Simple subscribe_json call raises a compiler error

I’m guessing you mean this example?

https://esphome.io/custom/custom_component.html#mqtt-custom-component

Assuming you have also included the #include, maybe this post will help: