Amine
Amine

Reputation: 2434

How to read .json file in React Native?

I am using React Native version 0.59.4. I created a file data.json

But when I import this file like this

import myData from '../staticData/data.json';

I get this error Bundle failed: Could not resolve module ... and I made sure the path is correct

I also tried removing the extension but no change

I tried almost every solution here.

Is there anything more that I can try?

EDIT I tried changing the extension from .json to .js and in that file I added export default { // json } and it worked like a charm.

Upvotes: 4

Views: 2736

Answers (1)

Well, you are doing it right, I think you are messing with the path. Are you sure that`s the right path, and how organized are your folders ???? another way to do that is to use the old JS way

const customData = require('./customData.json');

Upvotes: 2

Related Questions