Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda