Read <script> tag from website

Hello,

I have a website that puts all its API data into a script tag. For example:

<!DOCTYPE html>
<html>
<head>
<script type="application/ld+json">
{"UserDetails":{"name":"ben","lastname":"mitchell"},"Media":{"image":"https://example.com","video":"https://example.com"}}
</script>
</head>
</html>

I have been able to fetch the website successfully. My question now is, how do I take the response and parse it so that I can read that JSON data.

Essentially I want to be able to do something like

  1. Fetch the website
  2. Parse the HTML
  3. Parse the JSON from that HTML
  4. name = UserDetails.name
  5. image = Media.image

something like that.

Any ideas?