I think I'm way deep in the rabbit hole and I need...
# typescript
c
I think I'm way deep in the rabbit hole and I need someone to help me out with this super basic thing... I've got a resource that accepts a JSON.stringify() string. How do I read a json file in the same folder (call it
template.json
) into this property? I tried way too many things now and they all seem way too complex (SO answers usually are).
s
you can simply
import yourFile from "./yourFile.json"
which will allow you to use it as an (implicitly typed) variable make sure in your tsconfig you have this enabled:
Copy code
{
  "compilerOptions": {
    "resolveJsonModule": true
    ...
c
works like a charm, and was something I've been trying the whole time, but people skipped over the tsconfig
👍 1