1

I tried a lot to get data from the json file that is in inside the reactjs project folder I even tried getting json data of package.json file that is inside the reactjs folder but still got error How can I locate/get data from local JSON file I kept getting only error as output

 useEffect(() => {
    axios
      .get("http://localhost:3000/flat-trade/package.json")
      .then(function (response) {
        // handle success
        console.log(response + "hello");
      })
      .catch(function (error) {
        // handle error
        console.log("error");
      });
  });

1 Answer 1

3

If it is local file, you can directly import into react file

import * as data from './flat-trade/package.json';
Sign up to request clarification or add additional context in comments.

1 Comment

I tried it too but it said " Cannot convert object to primitive value" and I also did not get the data of the json :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.