[Samsung Galaxy J3 (2017) Questions & Answers] petmshall:
I managed to root this phone without TWRP. I used Linux tools to do this so I'm not sure if it could work on Windows.

Requirements:

Stock ROM for your phone (I used samfirm.js to pull it from the Samsung servers but downloading from sammobile.com works too)

A way to extract zip files

A way to extract tar files

Heimdall flasher (https://www.glassechidna.com.au/heimdall/)

Magisk Manager APK

An Internet connection on your phone

A compatible USB connector for your phone

Of course, a SM-J327W running the stock Android firmware

Obligatory warning: This WILL void the warranty of your phone and permanently trigger the warranty void flag. It also WILL cause a factory reset, so back up all your data first.

Bear with me, because there are a lot of steps. This will take around 15 to 30 minutes.

You will need to download and extract a stock ROM for your phone. Make sure that you download a ROM for the SM-J327W and not another model. Also make sure to download the latest version available.

Stock ROMs usually come in a zip file containing a few tar.md5 files. You will only need to extract the one that starts with "AP" for this procedure.

Step 1: Extract the tar.md5 file that starts with "AP" from your stock rom.

Step 2: Open the tar.md5 file in an archive manager. You may need to remove ".md5" from the end of the file.

Step 3: Extract the boot image (boot.img) from the AP file.

Step 4: Upload the boot image and the Magisk Manager APK to your phone. You can use ADB to transfer the files. For example:

adb push boot.img /storage/emulated/0

adb push Magisk-v22.0.apk /storage/emulated/0

Step 5: Open the files app on your phone. Navigate to the internal storage and tap on the Magisk APK file to install it. You may be prompted to allow installation from unknown sources.

Step 6: Open the Magisk app. It should say that Magisk isn't installed and it shoulld say "Yes" beside "Ramdisk". Tap the cogwheel icon in the top-right corner.

Step 7: Due to a bug in Magisk, you need to install version 21 instead of the latest version (v22). Set the update channel to "Custom Channel".

Step 8: When prompted, enter the following URL: "https://raw.githubusercontent.com/t...d863d3a15c6a2276b1061a280ece80ed7/stable.json" (Without the quotes.)

Step 9: Now it's time to patch the boot.img file. Tap the button to install Magisk and select the option to patch a file. When prompted, navigate to the internal storage and select the boot.img file that you transferred previously.

Step 10: Magisk will patch the file and tell you where it saved the patched file. Transfer the patched file to your computer. You can use ADB for this, for example:

adb pull /storage/emulated/0/Download/magisk_patched_XXXXX.img

Remember to replace the Xs with the the random characters that Magisk added to the file name.

Step 11: Reboot your phone into Download mode. You can shut it down and then hold the power, home, and volume down buttons at the same time to enter Download mode or use ADB: "adb reboot bootloader"

Step 12: A warning may show about the dangers of installing a custom OS. Press the volume up key to continue.

Step 13: The screen should now show "Downloading... Do not turn off target." If your phone isn't already plugged into your computer, plug it in now.

Step 14: Use Heimdall flasher to flash the patched boot image. For example:

heimdall flash --BOOT magisk_patched_XXXXX.img

Again, replace the Xs with the random characters that Magisk added to the file name.

Step 15: After a few seconds, Heimdall should report that the flash succeeded and your phone will reboot. It may take longer than usual. Leave it to do its thing and DO NOT pull out the battery.

Step 16: Your phone will show a notice that unauthorized changes have been detected and will prompt you to factory reset it. Press the button to perform the factory reset.

Step 17: Set up your phone as if it was new. It's not rooted yet, but you're really close if you got so far.

Step 18: Once you reach the home screen, upload the Magisk Manager APK to your phone again and install it like before.

Step 19: Open Magisk Manager. It will show that Magisk is installed and may prompt you to reboot to complete installation. Do not update Magisk to v22 or you will lose root access and you will have to flash the patched image again.

In the (very unlikely) case that your phone doesn't boot after flashing the patched boot.img, you can simply flash the original boot image and it should be fixed.

CONGRATULATIONS! You just rooted your SM-J327W successfully.

I also managed to port TWRP to this phone with the touchscreen working using the kernel from a recovery image for the SM-J327P found here: https://xdaforums.com/t/recovery-root-twrp-3-1-0-1-samsung-galaxy-j3-emerge-sm-j327p.3573607/. All the partitions are mapped correctly. Due to a bug (presumably with the kernel), the data partition can unfortunately only be mounted read-only. However, this shouldn't affect being able to flash zips on your phone and you can insert an SD card to write backups onto. In the future, I may port CWM recovery to this phone using the stock kernel to be able to mount the data partition read-write.

You can find my custom recovery attached to this reply.