Skip to content

Commit f5ec897

Browse files
Document JSON import
1 parent ff31a05 commit f5ec897

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pages/docs/manual/latest/json.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,33 @@ console.log(JSON.stringify([
5050

5151
</CodeTab>
5252

53+
### Import a JSON file
54+
55+
Use the `@module` attribute to import JSON files directly.
56+
57+
<CodeTab labels={["ReScript", "JS Output (Module)", "JS Output (CommonJS)"]}>
58+
59+
```res example
60+
@module external studentNames: JSON.t = "./students.json"
61+
Console.log(studentNames)
62+
```
63+
```js
64+
import * as StudentsJson from "./students.json";
65+
66+
var studentNames = StudentsJson;
67+
68+
console.log(studentNames);
69+
```
70+
```js
71+
var StudentsJson = require("./students.json");
72+
73+
var studentNames = StudentsJson;
74+
75+
console.log(studentNames);
76+
```
77+
78+
</CodeTab>
79+
5380
## Advanced
5481

5582
Thanks to untagged variants, JSON can be encoded and decoded idiomatically. Check it out on [the variants page](variant#decoding-and-encoding-json-idiomatically).

0 commit comments

Comments
 (0)