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

147
Visualizações
Generated json object retuning number as string

I have this vue method that takes input vales from user and generates a json object before it performs the axios put request. My issue is that the json object generated is returning numbers as strings, and that breaks my API response. My goal is for my json object to be like this:

{
  "test":{
    "test1":{
      "test2":2,
      "test3": 2
    }
  }
}

On current code, json object returns like this (2 as string):

{
  "test":{
    "test1":{
      "test2":"2",
      "test3":"2"
    }
  }
}

This is my vue method:

generateJson() {
  const values = {}

  this.inputs.forEach((item) => {
    values[item.key] = item.value
  })

  const jsonFile = {
    test: {
      test1: values
    }
  }

    const testUrl = '*URL placeholder*'

    axios.put(testUrl, jsonFile).then((response) => {
      console.log(response.data)
    })
  }
}

This is the user input field:

    <button @click.prevent="showInput">+</button>
    <div v-for="(input, k) in inputs" :key="k">
        <input v-model="input.key" type="text" @change="getKey($event)" />
        <input
              v-model="input.value"
              type="text"
              @change="getValue($event)"
            />
    </div>

</div>
<button @click.prevent="generateJson">Submit</button>

And here is the other two methods that i use to get the value from input:

data() {
  return {
    tempkey: '',
    tempValue: '',
  }
}
getKey(e) {
  this.tempkey = e.target.value
},
getValue(e) {
  this.tempValue = e.target.value
},

Anyone can advise what i can do to make this work? Many thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Inputs of type 'text' will return a string. Try changing the input type to number. Otherwise, you could do this (with type text):

getKey(e) {
 this.tempkey = parseInt(e.target.value)
}
getValue(e) {
 this.tempValue = parseInt(e.target.value)
}
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