TypeScript Compiler Options
resolveJsonModule — TypeScript compiler option
Enables JSON module resolution and infers a type from its static shape. Runtime JSON support depends on host and module format; this is not validation of arbitrary JSON text obtained later. Default (5.8.3): depends on moduleResolution (true by default in Bundler). Create the labeled files in an isolated local project and run tsc -p tsconfig.json. Expected: no diagnostics; emitted files: dist/main.js, dist/settings.json. Run node dist/main.js; expected stdout: '7'. Local multi-file fixture, not a single-file editor.
Formal Syntax & Structure
typescript syntaxtypescript
{ "compilerOptions": { "resolveJsonModule": true }}Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| resolveJsonModule | boolean | Set in compilerOptions; default: depends on moduleResolution (true by default in Bundler). |
Working Example
Example Snippettypescript
// File: tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "strict": true, "types": [], "noEmitOnError": true, "resolveJsonModule": true, "outDir": "dist" }, "files": [ "main.ts" ]}// File: main.tsimport settings = require("./settings.json"); const checked: number = settings.count; console.log(checked);// File: settings.json{ "count": 7}