Next.js Discord

Discord Forum

Error (JSON?)

Unanswered
Bumble bee posted this in #help-forum
Open in Discord
Bumble beeOP
 ⨯ SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at parseJSONFromBytes (node:internal/deps/undici/undici:6662:19)
    at successSteps (node:internal/deps/undici/undici:6636:27)
    at specConsumeBody (node:internal/deps/undici/undici:6642:9)
    at NextRequest.json (node:internal/deps/undici/undici:6533:18)
    at GET (webpack-internal:///(rsc)/./src/app/api/cities/route.ts:16:30)


// Städte auflisten
export async function GET(request: NextRequest, route: NextRoute) {
    // JSON-Daten auslesen
    const {} = await request.json()

    // Parameter auslesen
    const {} = route.params

    // Datenbank auslesen
    const cities = await database.city.findMany({
        where: { deletedAt: null },
        orderBy: { slug: 'asc' }
    })

    // JSON-Daten zusammenfassen
    const data = { cities }

    // JSON-Daten zurückgeben
    return NextResponse.json({ data })
}


What's the problem here?

3 Replies

Bumble beeOP
why can't I do: const {} = await request.json() ?
Bumble beeOP
or ... why 500 Internal Server Error ? :lolsob:
i don't think you can have body content in a GET request and the error is because you are tying to access the body and convert it to json.