I am re-writing an existing js app into angular and ts. I have a json data file that I read as part of the startup of the existing js app and it works fine. When I try and read the exact same file with the exact same line of code in angular, ts/angular barfs all over it. Here is the code from the existing app:
aircraftData = JSON.parse(data);
and the console log is empty. Here is the the code from the new angular version of the app:
const content = require('./shared/imeiXref.json');
console.log("IMEI=",content[0].IMEI);
and the console output:
AppComponent_Host.ngfactory.js? [sm]:1 ERROR SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at AppComponent.push../src/app/app.component.ts.AppComponent.ngOnInit (app.component.ts:33)
at checkAndUpdateDirectiveInline (core.js:22089)
at checkAndUpdateNodeInline (core.js:23353)
at checkAndUpdateNode (core.js:23315)
at debugCheckAndUpdateNode (core.js:23949)
at debugCheckDirectivesFn (core.js:23909)
at Object.eval [as updateDirectives] (AppComponent_Host.ngfactory.js? [sm]:1)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:23901)
at checkAndUpdateView (core.js:23297)
View_AppComponent_Host_0 @ AppComponent_Host.ngfactory.js? [sm]:1
proxyClass @ compiler.js:18234
push../node_modules/@angular/core/fesm5/core.js.DebugContext_.logError @
core.js:24129
push../node_modules/@angular/core/fesm5/core.js.ErrorHandler.handleError @ core.js:15762
(anonymous) @ core.js:18116
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @
zone.js:391
.....
Is JSON expected to be in a different format from js to angular/ts?
Thanks....