Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading Local JSON in Angular on Stackblitz

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
like image 696
Ole Avatar asked Jan 31 '26 13:01

Ole


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

like image 90
Poul Kruijt Avatar answered Feb 03 '26 01:02

Poul Kruijt