Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

218
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

Try this:

data: `{"event": "game mode", "customer_properties": {"$email": ${fetch_email}}}`
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda