Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!