JSON data post by CURL

Asked

Viewed 27 times

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:

Error
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)

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

  • 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 &#39; in JSON at position 0<br> &nbsp; &nbsp;at JSON.parse (&anonymous&lt;)<br> &nbsp;at createStrictSyntaxError

  • (C: Users motad Appdata Roaming npm node_modules json-server node_modules body-parser lib types json.js:158:10)<br> &nbsp; &nbsp;at parse (C: Users motad Appdata Roaming npm node_modules json-server node_modules body-parser lib types json.js:83:15)<br> &nbsp; &nbsp;at C:Users motad Appdata Roaming npm node_modules json-server node_modules body-parser lib read.js:121:18<br> &nbsp;at invokeCallback (C: Users motad Appdata Roaming npm node_modules json-server node_modules raw-body index.js:224:16)<br> &nbsp; &nbsp;at done

  • (C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\raw-body\index.js:213:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (C:\Users\motad\AppData\Roaming\npm\node_modules\json-server\node_modules\raw-body\index.js:273:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (Events.js:327:22)<br> &nbsp; &nbsp;at endReadableNT (Internal/streams/readable.js:1327:12)<br> &nbsp; &nbsp;at processTicksAndRejections (Internal/process/task_queues.js:80:21)</pre> </body> </html>

  • Better update the post, instead of using the comments for this.

  • 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?

  • 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.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.