Reputation: 1251
Sample
variable but only first few characters are displayed from Sample
variable. Sample
variable on Console only first 3,756 characters are printed.Is there any limitations on the characters that can be printed through console.log?Complete data persists in Sample variable
, I verified it by searching for strings that occur at the end of sample.json
file
var Sample = require('./sample.json');
export default class proj extends Component {
constructor(props) {
super(props);
this.state = {
locations: [],
};
}
loadOnEvent() {
console.log(Sample);
//this.state={ locations : Sample };
}
}
Is there any other way to print data in Sample
variable.
Upvotes: 1
Views: 1067
Reputation: 68
You have to convert json to string using JSON.stringify
before logging.
/* ... */
loadOnEvent() {
console.log(JSON.stringify(Sample));
//this.state={ locations : Sample };
}
/* ... */
Upvotes: 2
Reputation: 8240
Try to use another way to load. Use fetch
if file is remote or use fs
if file is local.
If it is memory problem supposed by @Shota consider to use server side processing requests to json file. It is good solution to setup microservice which load json file at startup and handle requests to data struct parsed from json file.
Answer for webpack use case:
Configure webpack to use file-loader
or copy-webpack-plugin
for specifically this file because it enough big. Consider to load it in parallel with webpack bundle. If your application have big parts which need not each case they must be moved to separated bundles.
Upvotes: 0