The two injectors look similar but carry different part numbers. You do need to ensure you get the right injector, the D40 fuel pump can generate 1700BAR (over 24,000 psi).
There is a seller on eBay that says the D40 injector will fit the D22 - and I'd imagine that would be safe to do, because the D40 injector is designed for higher pressures than the D22 can generate. However I would be reluctant to go the other way, and try a D22 injector in the D40.
All of this assumes that Nissan and Denso haven't simply created a new part number for the same part that goes in a different car (so the injector is tooled up the same, making production cheap, and just marked differently). If that's the case, your D22 injectors should be fine.
Do you have any part numbers on the injectors? Both sets if you can. The D40 ones should be 16600-5X000 (Nissan) or 295050-0300 (Denso).