Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!