Promise in JSON.stringify help

I wrote the following code (I simplified it for the example).
Since func2 returns a promise I won’t have its value when sending data to the server, I’d like the data to be sent only after func2 resolved.
How can I handle it ? (without using await, .then is fine)

function func1()
{
    return 1;
}

async function func2()
{
    return 2;
}

var data = JSON.stringify({
    "request": [{
        "resource": "www.example.com", "parameters": {
            func1: func1(),
            func2: func2() //???
        }
    }]
});

//send data to external server..

Then you should resolve func2 first.

func2()
  .then(func2Value => {
    const data = JSON.stringify({
      "request": [{
        "resource": "www.example.com", "parameters": {
          func1: func1(),
          func2: func2Value
        }
      }]
    });
  
    //send data to external server..
  });
1 Like