Using a macbook SSD as a replacement in iMac
According to this definitive guide of Apple SSD modules:
https://beetstech.com/blog/apple-proprietary-ssd-ultimate-guide-to-specs-and-upgrades
your iMac can use the 'Generation 5' SSD module that comes in your MBP, even though the iMac originally comes with 'Generation 4'.
Don't forget that if you replace one part of a Fusion Drive, the data on the 'volume' is entirely lost, so make sure you've got a backup before starting. (I'd recommend keeping the hard drive as a separate volume from now on.)
However, if you want to save yourself the bother of opening up the iMac, an external Thunderbolt drive may be just as fast.