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.
#
ExampleConsider the following project files:
#
Modifying tsconfig.jsonTo be able to import JSON files you have to enable the resolveJsonModule
option in tsconfig.json, and set moduleResolution
to node:
tsconfig.json
#
Json dataThe file containing JSON is just standard JSON:
myjsondata.json
#
Importing JSON dataNow to access your data, simply import it from your TS file:
main.ts