Search code examples
javascriptjsontestingautomated-teststestcafe

Console log json value


I'm working with Testcafe and I would like to ask how to display on the console a json value. For example, I have this link "https://jsonplaceholder.typicode.com/users" I want to console the first username or all usernames for example. Best regards!


Solution

  • try with {}

    fetch('https://jsonplaceholder.typicode.com/users')
     .then(resp => resp.json()) 
     .then(data => {
       console.log( JSON.stringify( data , 0, 2))
       }) 
    

    to only usernames

    fetch('https://jsonplaceholder.typicode.com/users')
     .then(resp => resp.json()) 
     .then(data =>
      {
      data.forEach(el=>console.log(el.username) )
      })