0
I’m starting to use JSON-SERVER, I don’t have much knowledge yet. I’m trying to make a JSON data POST with CURL in windows cmd. I’m using the following code:
curl -d "{"nome":"usuario1", "idade":40, "sexo":"feminino"}" -H "Content-type: application/json" -X POST http://localhost:3000/usuarios
In the window I run the above code appears this error:
ErrorSyntaxError: Unexpected token n in JSON at position 1
at JSON.parse (<anonymous>)
at parse (C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\body-parser\lib\types\json.js:89:19)
at C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\body-parser\lib\read.js:121:18
at invokeCallback (C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\raw-body\index.js:224:16)
at done (C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\raw-body\index.js:213:7)
at IncomingMessage.onEnd (C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\raw-body\index.js:273:7)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
In the node window where the server is running the following error appears:
POST /usuarios 400 2.150 ms - 1111
SyntaxError: Unexpected token n in JSON at position 1
at JSON.parse (<anonymous>)
at parse (C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\body-parser\lib\types\json.js:89:19)
at C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\body-parser\lib\read.js:121:18
at invokeCallback (C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\raw-body\index.js:224:16)
at done (C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\raw-body\index.js:213:7)
at IncomingMessage.onEnd (C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\raw-body\index.js:273:7)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (internal/streams/readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
I have looked but still not found how to solve this error
Change of
"{"nome":"usuario1", "idade":40, "sexo":"feminino"}"
for'{"nome":"usuario1", "idade":40, "sexo":"feminino"}'
, that is to say of"
for'
that involves the json– Paulo Marques
Now this error appears in the window I run the code: Curl: (3) Port number ended with ',' Curl: (3) [globbing] Unmatched close Brace/Bracket in column 14 <! DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>Syntaxerror: Unexpected token ' in JSON at position 0<br> at JSON.parse (&anonymous<)<br> at createStrictSyntaxError
– eduardo_2382
(C: Users motad Appdata Roaming npm node_modules json-server node_modules body-parser lib types json.js:158:10)<br> at parse (C: Users motad Appdata Roaming npm node_modules json-server node_modules body-parser lib types json.js:83:15)<br> at C:Users motad Appdata Roaming npm node_modules json-server node_modules body-parser lib read.js:121:18<br> at invokeCallback (C: Users motad Appdata Roaming npm node_modules json-server node_modules raw-body index.js:224:16)<br> at done
– eduardo_2382
(C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\raw-body\index.js:213:7)<br> at IncomingMessage.onEnd (C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\raw-body\index.js:273:7)<br> at IncomingMessage.emit (Events.js:327:22)<br> at endReadableNT (Internal/streams/readable.js:1327:12)<br> at processTicksAndRejections (Internal/process/task_queues.js:80:21)</pre> </body> </html>
– eduardo_2382
Better update the post, instead of using the comments for this.
– Paulo Marques
how so? excuse the question but I’m still starting in this part of HTTP, I would have to explain to me how to do this?
– eduardo_2382
At the end of your post there is a link to edit it. Use it to update with the error messages and what you did.
– Paulo Marques