Loading Local JSON in Angular on Stackblitz

Viewed 698

In general as noted here it's pretty straight forward:

import data from './data.json';

However this does not work in Stackblitz Angular projects.

The linked project logs the following:

preview-3a0c9433aa42f56dbd90b.js:1 SyntaxError: Unexpected token o in JSON at position 1
1 Answers

When importing, you should not use JSON.parse(). It's already parsed by cli/webpack

import data from './data.json';

test: any = data;

stack

Related