Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

213
Visualizações
JSON on post data attach the string on it

Hey I am new to JSON and for this project I am using POST using a variable fetch_email inside the customer_porperties. Currently if I send out the value as {"$email": "sunny@gmail.com"} , it gets submitted. But if I use var fetch_email = "sunny@gmail.com" and call it on {"$email": fetch_email} , it does not submit and throws an error. What's the better way to call the variable inside the const body data for JSON ? Can anyone please help on it ?

const options = {
        method: 'POST',
        headers: {Accept: 'text/html', 'Content-Type': 'application/x-www-form-urlencoded'},
        body: new searchParams({
          data: '{"event": "game mode", "customer_properties": {"$email": fetch_email}}'
        })
      };

      fetch('https://thrid_party/api', options)
        .then(response => response.json())
        .then(response => console.log(response))
        .catch(err => console.error(err));
      
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Don't manually build JSON strings, use the built-in JSON.stringify().

body: new searchParams({
    data: JSON.stringify({"event": "game mode", "customer_properties": {"$email": fetch_email}})
})
about 4 years ago · Juan Pablo Isaza Relatório

0

Try this:

data: `{"event": "game mode", "customer_properties": {"$email": ${fetch_email}}}`
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda