Comment

Jack

My immediate thought was why not do something like this, but then I thought for the sake of repetition and clarity your solution makes more sense.

import json
import requests

response = requests.get(url)
try:
    print(response.json())
except (json.decoder.JSONDecodeError, ValueError):
    print("N'est pas JSON")