Skip to main content

Importing JSON Modules

TypeScriptToLua supports importing JSON files into your TypeScript. This is done by translating the JSON file to Lua and simply including this Lua file as part of the transpiler output.


Consider the following project files:

├── main.ts
├── myjsondata.json
└── tsconfig.json

Modifying tsconfig.json

To be able to import JSON files you have to enable the resolveJsonModule option in tsconfig.json, and set moduleResolution to node:

"compilerOptions": {
"moduleResolution": "node",
"resolveJsonModule": true

Json data

The file containing JSON is just standard JSON:

"property1": "foo",
"property2": "bar"

Importing JSON data

Now to access your data, simply import it from your TS file:

import * as myJson from "./myjsondata.json";

const p1 = myJson.property1;