Categories
React Answers

How to import JSON file in React?

Spread the love

Sometimes, we want to import JSON file in React.

In this article, we’ll look at how to import JSON file in React.

How to import JSON file in React?

To import JSON file in React, we use import to import it like a regular module.

For instance, we write

import Profile from "./components/profile";

to import the ./components/profile JSON file as Profile.

This works because the json-loader Webpack module is included with create-react-app.

Conclusion

To import JSON file in React, we use import to import it like a regular module.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.