I have not tried to implement the JSON-LD as yet. But in my mind, I would create the script and replace the static values for dynamic values using the same logic as here.
In this way, each time the URL changes, so will the values within the script.
Edit: This may help: https://www.youtube.com/watch?v=i8P-B5aa5E0