From 331898f40e36daedc671271ebc6d0821872f2c58 Mon Sep 17 00:00:00 2001 From: Max Thirouin Date: Sun, 17 Jan 2021 08:51:28 +0100 Subject: [PATCH] Add "Import a JSON file content" to "Import From JavaScript" page Could be handy for new comers or eternal newbies like me. --- .../latest/import-from-export-to-js.mdx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pages/docs/manual/latest/import-from-export-to-js.mdx b/pages/docs/manual/latest/import-from-export-to-js.mdx index 0d9938f06..2963d8ce8 100644 --- a/pages/docs/manual/latest/import-from-export-to-js.mdx +++ b/pages/docs/manual/latest/import-from-export-to-js.mdx @@ -70,6 +70,25 @@ console.log(Student.default); +### Import a JSON file content + +Use the `bs.module` [external](external.md): + + + +```res example +type dataType +@bs.module external studentNames: dataType = "./students.json" +Js.log(studentNames) +``` +```js +var StudentsJson = require("./students.json"); +var studentNames = StudentsJson; +console.log(studentNames); +``` + + + ## Export To JavaScript As mentioned in ReScript's idiomatic [Import & Export](import-export.md), every let binding and module is exported by default to other ReScript modules. If you open up the compiled JS file, you'll see that these values can also directly be used by another _JavaScript_ file too.