Consider using '--resolveJsonModule' to import module with '.json' extension.ts(2732) code example

Example 1: Consider using '--resolveJsonModule

add "resolveJsonModule": true key in tsconfig.json

{
  "compilerOptions": {
    "target": "es2015",
    "module": "commonjs",
    "strict": true,
    "moduleResolution": "node",
    "resolveJsonModule": true
  }
}

Example 2: read json file in typescript

// data.json:
{
"greeting" : "xin chao Vietnam"
}
// component:
import * as data from 'data.json';
let greeting = data.greeting;
//registering jsonModule in tsconfig.json
"compilerOptions": {
    ....
    "resolveJsonModule": true,
    ....
  },

Example 3: typescript read json file

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

Example 4: --resolveJsonModule

declare module "*.json" {
  const value: any;
  export default value;
}