Can I install a LED Transformer in a junction box?
Some are.  You can also get transformers designed to mount into a 1/2” knockout in a junction box.  The transformer proper sits outside the box. You can also find transformers which sit on the outside of a metal box cover.   These are very common in 24VAC.   

These are typically true transformers.   You may be using the word "transformer" loosely to mean any low voltage power supply.  That may be a bit harder to find.  

Any device you put on 120V power should be UL listed for the purpose, or inside a listed metal enclosure.  

Another option, if there is a metal fixture involved, is to mount the power unit inside the fixture.   

You do need to watch out for box fill limitations.   Don't overstuff the box.