0

I am importing a json file via:

import * as menuJson from './menu.json';

If console.log menuJson I get:

enter image description here

If I try to console.log menuJson.default I get:

enter image description here

The error is:

Property 'default' does not exist on type 

How can I turn turn this back into regular json and not a module so I can access the json content?

bstras21
  • 981
  • 3
  • 11
  • 32
  • Does this answer your question? [Angular 5 Service to read local .json file](https://stackoverflow.com/questions/47206924/angular-5-service-to-read-local-json-file) – TotallyNewb Feb 08 '21 at 10:26

1 Answers1

0

If your Typescript version is 2.9+, you can Do the followings:

Add these to your compilerOptions in tsconfig.json file:

"resolveJsonModule": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true

and import your json:

import menu from './menu.json';
Saghi Shiri
  • 537
  • 5
  • 19