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

530
Views
How to get JSON content and display it in React?

I'm making an app using React JS. It's basically supposed to get JSON content and display it in the screen. I know this is supposed to be something really simple, but I am just unable to implement it. Please look into my code and show a way to import and display this JSON in my React. Thanks!!

JSON

[
  {
    "id": "1",
    "title": "Test",
    "firstName": "Testing",
    "lastName": "Thingy",
    "salary": 5000
  },
  {
    "id": "2",
    "title": "Test",
    "firstName": "Test",
    "lastName": "Thing",
    "salary": 6000
  }
]

React JS code in a minimal reproducible example -

import thing from "./card.json";

const item = JSON.stringify(thing[0][1]);
const item2 = JSON.stringify(thing[1]);

const ProductCard = ({ data }) => {
  return (
    <div>
      <h1>{item}</h1>
      <h1>{item2}</h1>
    </div>
  );
};

export default ProductCard;

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

If all the objects in JSON is the same you can use the map function. It could look something like.

import thing from "./card.json";

const ProductCard = ({ data }) => {
  return (
      <div>
        {data.map(jsonObject => {
            return(
                <div>
                    <h1>{jsonObject.title}</h1>
                    <p>{jsonObject.id}</p>
                    <p>{jsonObject.firstName}</p>
                    <p>{jsonObject.lastName}</p>
                    <p>{jsonObject.salary}</p>
                </div>
                )
            })
        }
      </div>
  );
};

export default ProductCard;
about 4 years ago · Juan Pablo Isaza Report

0

Hey the above format of JSON is object inside a array so we can access the array elemnet using things[0] but for for object we need to provide the key. In above you don't need to Stringify the JSON.

import thing from "./card.json";

const item = thing[0].id;
const item2 = thing[1].title;

const ProductCard = ({ data }) => {
  return (
    <div>
      <h1>{item}</h1>
      <h1>{item2}</h1>
    </div>
  );
};

export default ProductCard;
about 4 years ago · Juan Pablo Isaza Report

0

if you wants to get value of one field use this code:

const item = data[0].id;

but if you wants to read all object as string use this sample:

const item2 = JSON.stringify(data[1]);
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!