To start with your iMac has a 2 lane PCIe blade SSD interface and your MacBook Air has a 4 lane PCIe blade SSD blade drive (interface). I would be hesitant to recommend opening your system for such major surgery with the gamble of this not working as the lane widths are different. You would be putting in a newer version of SSD into a system which may not be able to support it.
Here are images of the iMac SSD:
Here are images of the MB Air SSD:
While they look the same they may not be interchangeable.
The second issue is Apple configured your system with a Fusion drive set. By combining your traditional platter drive (HD) with your solid state drive (SSD) as one drive logically. You will need to break the Fusion drive set before you can swap out the SSD.
The third issue here is this is a bear of a system to open! If you've never opened one before you could damage the display unit which would be an expensive mistake. In addition you'll need to completely remove the logic board to gain access to the blade SSD. Here is the IFIXIT guide I would strongly recommend you review: iMac Intel 27" Retina 5K Display SSD Replacement.
OK what to do?
How about just going with an external drive, a Thunderbolt2 SSD RAID set will offer the same if not better performance on what you could do internally.