SyntaxError: Unexpected end of JSON input","

Hi! My netlify functions are deployed and were working before. But now they are returning error 502 SyntaxError: Unexpected end of JSON input"," whenever I call POST method. It does save the data in Supabase database but doesnt return the JSON object.

Kindly guide me why it causing this issue?.
Thanks

Hi @aff_cue :wave:t6: ,

Welcome to the forums and thank you so much for reaching out. Did you search the forums and see if any of the other solutions helped? Have you looked through this resource? It is a compilation of all of our build and deploy resources. This is a good starting point.

If you have worked through those guides and are still encountering issues please share the following information:

  • the name of your build instance: “example-jones.netlify.com”
  • what you have already tried
  • any error messages you have received in your terminal window or in the developer console

@aff_cue The error is as you’ve pasted in:

SyntaxError: Unexpected end of JSON input

Look in your code for somewhere you are trying to parse a json string into an object.
Ensure that the string is actually a valid json structure.

1 Like

@nathanmartin Im not doing JSON.parse. The response is coming like this
Object {
“data”: null,
“errors”: Array [
Object {
“extensions”: Object {
“code”: “INTERNAL_SERVER_ERROR”,
“exception”: Object {
“clientVersion”: “2.30.3”,
},
},
“locations”: Array [
Object {
“column”: 3,
“line”: 3,
},
],
“message”: “Unexpected end of JSON input”,
“path”: Array [
“updateUser”,
],
},
],
}

when I hit https://{myAppDomain}/.netlify/functions/{functionName}

It does save the values that I sent to body. But returns this above response.

The error indicates that something is trying to consume some JSON, and is unable to do so because it is malformed.

While it may not be “you” directly, if it’s a function that you’ve deployed, then it’s still likely to be within your code, even if it were a function that was automatically deployed by a system that you’d just chosen to work with.

So if it’s what you see as the response given by a function that you’ve created yourself, you should debug the code of that particular function.

Hi I was working on a discord bot project and then my bot wouldn’t refresh anymore, it kept saying this from the console

SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at /opt/watcher/source/app-picker.ts:105:37
at ChildProcess.exithandler (child_process.js:285:7)
at ChildProcess.emit (events.js:189:13)
at ChildProcess.EventEmitter.emit (domain.js:441:20)
at maybeClose (internal/child_process.js:970:16)
at Socket.stream.socket.on (internal/child_process.js:389:11)
at Socket.emit (events.js:189:13)
at Socket.EventEmitter.emit (domain.js:441:20)
at Pipe._handle.close (net.js:597:12)

I don’t know if someone can fix this someone suggest me this Understanding "Unexpected End of JSON Input" Error

Hi, @corinnaucdjv. Unfortunately, that is not enough information to troubleshoot. Would you please tell us a URL where we can see this error?

You can post that information publicly or you can private message (PM) that to one of our support staff. I’ve confirmed that PMs are enabled for your forum login. Please keep in mind that only one person can see the PM and this will likely mean a slower reply than posting the information publicly. Please feel free to reply to however you prefer though.

The error message “unexpected end of JSON input” maybe misleading in this case. It appears the response is already in a valid javascipt object format, not a JSON string. You can directly access the properties of the object without needing to parse it. Plus, to enhance your chatting experience, you gotta download an whatsapp from anwtapk.

For example, to access the error message:

const response = {
  "data": null,
  "errors": [
    {
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "clientVersion": "2.30.3",
        },
      },
      "locations": [
        {
          "column": 3,
          "line": 3,
        },
      ],
      "message": "Unexpected end of JSON input",
      "path": [
        "updateUser",
      ],
    },
  ],
};

console.log(response.errors[0].message); // Output: "Unexpected end of JSON input"

The error can obviously be in code that’s not yours, which itself may be using JSON.parse

What does your function do?
Is there a URL that can be tested?
Public repository that can be looked at?