Page 1 of 1

Unexpected token in JSON

Posted: Fri Oct 08, 2021 12:42 pm
by randyh
Is there a simple way to check if the value of an object has been passed in node js? It does not seem to matter if the object in the module is defined as character or decimal.

For example, within the body of a request

{
"quantity": 1,
"weight": 100
}

when looking at the object "quantity": 1 ,
the error occurs when in the body of the request my client passes "quantity" : , specifying no value for quantity

{
"quantity": ,
"weight": 100
}

Re: Unexpected token in JSON

Posted: Fri Oct 08, 2021 6:26 pm
by Scott Klement
Randy,

Code: Select all

{
"quantity": ,
"weight": 100
}
This is not a valid JSON object. It violates the syntax rules of the JSON standard. Nothing will be able to read this.

Fix whatever is creating the document like that.