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

179
Vistas
how to display our data in json format

am new in next JS , I want to display my index.js file data in dynamicid.js file in JSON format , can anyone tell me how can I display it.

index.js

This is the index.js file where My output is displayed, but I want to display my output data in particular route in JSON Format.

import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'

import { getDataFromSheets} from './libs/sheets'

export default function Home({data}) {
  return (
    <div className={styles.container}>
      <Head>
        <title>Nextsheet 💩</title>
        <meta
          name="description"
          content="Connecting NextJS with Google Spreadsheets as Database"
        />
        <link rel="icon" href="/favicon.ico" />
      </Head>

      <main>
        <h1>Welcome to Nextsheet 💩</h1>
        <p>Connecting NextJS with Google Spreadsheets as Database</p>
        <ul>
          {data && data.length ? (
            data.map((item) => (
              <li key={item}>
                {item.title} - {item.description} 
              </li>
            ))
          ) : (
            <li>Error: do not forget to setup your env variables 👇</li>
          )}
        </ul>
      </main>
    </div>
  )
}
// console.log(process.env.NAME);
export async function getStaticProps(context) {
 
  const sheet = await getDataFromSheets();
  return {
    props: {
      data: sheet.slice(0, sheet.length), // remove sheet header
    },
    revalidate: 1, // In seconds
  };
}

dynamicid.js

This is my route file where I want to display my data in JSON Format.

export default  function handler(req, res) {


  res.status(200).json(name : "Ashish")
  
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

the json method on res accepts a javascript object. your current implementation is not a valid JS. to fix it use the following:

  res.status(200).json({name : "Ashish"})
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