Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
Node.JS SyntaxError: Unexpected token i in JSON at position 20

Something weird happened with my code || environment. The following code was working fine yesterday.

app.get('/', async (req, res)=>{
    const catalog = {
        kitchen: await knex('kitchen').distinct('item_group'),
        bedroom: await knex('bedroom').distinct('item_group'),
        living_room: await knex('living_room').distinct('item_group'),
        kidsroom: await knex('kidsroom').distinct('item_group'),
        bathroom: await knex('bathroom').distinct('item_group'),
        accessories: await knex('accessories').distinct('item_group')
    }
    res.json(catalog)
})

The next day, GET request replies with:

SyntaxError: Unexpected token i in JSON at position 20
    at JSON.parse (<anonymous>)
    at parse (C:\Users\User\Desktop\Apps\SmartWebsite\node_modules\body-parser\lib\types\json.js:89:19)
    at C:\Users\User\Desktop\Apps\SmartWebsite\node_modules\body-parser\lib\read.js:121:18
    at invokeCallback (C:\Users\User\Desktop\Apps\SmartWebsite\node_modules\raw-body\index.js:224:16)
    at done (C:\Users\User\Desktop\Apps\SmartWebsite\node_modules\raw-body\index.js:213:7)
    at IncomingMessage.onEnd (C:\Users\User\Desktop\Apps\SmartWebsite\node_modules\raw-body\index.js:273:7)
    at IncomingMessage.emit (events.js:412:35)
    at endReadableNT (internal/streams/readable.js:1317:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)

I have the following frameworks/dependencies installed:

const express = require('express')
const mysql = require('mysql2/promise')
const app = express()
const port = 3000

app.use(express.json())

The problem is happening with all projects in my computer which were working fine so far.

I tried:

  • restarting computer ;)
  • uninstalling and reinstalling frameworks and dependencies
  • JSON.parse(object)
  • JSON.stringify(object)

Thank you in advance for your help!

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

First of all

const catalog = {
        kitchen: await knex('kitchen').distinct('item_group'),
        accessories: await knex('accessories').distinct('item_group')
        ...
    }

instead, assign each of the query to a new variable, then check if they are all working by simply console logging.

about 4 years ago · Juan Pablo Isaza Denunciar

0

The problem seemed to be with Postman's cache memory. After sending a GET request from the browser everything was back in order. I closes old windows in Postman and sent new requests from new windows. It is working fine again.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda