0

i am trying to figure out how to extract the json data from the following:

HTML RESPONSE

<html><body>
<pre style="word-wrap: break-word; white-space: pre-wrap;">
{'name':'john doe'}
</body></html>

I have Tried

document.body.innerHTML which returns null

and

document.body.outerHTML which returns

<body><pre style="word-wrap: break-word; white-space: pre-wrap;">{'name:'john doe'}</body>

What i want as a string

{'name':'john doe'}

Any help will be highly appreciated.

austin
  • 517
  • 5
  • 16

1 Answers1

2

try this,

in your html

<html><body>
<pre style="word-wrap: break-word; white-space: pre-wrap;">
{"name":"john doe"} </pre>
</body></html>

in your js

const pre = document.querySelector('pre')
console.log(pre.innerText) // you can also use pre.textContent

checkout Difference between textContent vs innerText: Difference between textContent vs innerText

Vinod Liyanage
  • 945
  • 4
  • 13