I have a react app where I am making a post call to an api. My post sends a key value object that is converted to json using JSON.stringify. This properties represent the fields in a database and values are numeric in some cases. My problem is that I get a 400 error.
I suspect this is because the json object I am passing looks like this:
let data =
{
"field1": "value1",
"field2": "value2",
"count": "47"
}
I'm setting these property values from state like so:
let data =
{
"field1": state.value1,
"field2": state.value2,
"count": state.value3
}
However, count in my database table where the object is being posted to is a number field.
To test this theory, I created a hardcoded object that looks like the following and when I post that it works just fine:
let data =
{
"field1": "value1",
"field2": "value2",
"count": 47
}
Javascript is not typed so how can I create an object that looks like the one above where non string values are not enclosed in quotes?