Skip to content

Commit

Permalink
Document JSON import
Browse files Browse the repository at this point in the history
  • Loading branch information
fhammerschmidt committed Jun 12, 2024
1 parent ff31a05 commit f5ec897
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pages/docs/manual/latest/json.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,33 @@ console.log(JSON.stringify([

</CodeTab>

### Import a JSON file

Use the `@module` attribute to import JSON files directly.

<CodeTab labels={["ReScript", "JS Output (Module)", "JS Output (CommonJS)"]}>

```res example
@module external studentNames: JSON.t = "./students.json"
Console.log(studentNames)
```
```js
import * as StudentsJson from "./students.json";

var studentNames = StudentsJson;

console.log(studentNames);
```
```js
var StudentsJson = require("./students.json");

var studentNames = StudentsJson;

console.log(studentNames);
```

</CodeTab>

## Advanced

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 comments on commit f5ec897

Please sign in to comment.