typescript get json from file code example
Example 1: 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 2: how to import a json string from a file in typescript
import {default as a} from "a.json";
a.primaryMain
Example 3: typescript read json file
import {default as a} from "config.json";
config.targetKey
// this requires `"resolveJsonModule": true` in tsconfig.json