Here is an example of a simple Python script that uses nRF Util to program all connected J-Link supported devices with a file firmware.hex and print the results:
import json
import subprocess
firmware_path = "firmware.hex"
# Program all connected jlink devices and collect the output
output = subprocess.run(["nrfutil", "device", "program",
"--json", "--traits", "jlink",
"--firmware", firmware_path],
capture_output=True)
stdout_as_lines = output.stdout.decode("utf-8").split("\n")[0:-1]
for line in stdout_as_lines:
parsed_line = json.loads(line)
# Find the lines indicating that a task ended
if parsed_line["type"] == "task_end":
# Print the results of the operation
print("{}: {}".format(parsed_line["data"]["task"]["description"],
parsed_line["data"]["result"]))
For more Python examples of using the JSON output from nrfutil device, see the command guide, also available when you run nrfutil device --help-extended.