Search code examples
docusaurus

Link to static JSON file


In Docusaurus V2 how to link to a JSON file in the static folder?

I tried the following in a markdown file:

An exemple, is the following [JSON dataset](../../static/data/solar-radiation.json).

But Docusaurus then produce the following error:

./static/data/solar-radiation.json (./node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[hash].[ext]!./static/data/solar-radiation.json)
Module parse failed: Unexpected token e in JSON at position 0 while parsing near 'export default __web...'
File was processed with these loaders:
 * ./node_modules/file-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
SyntaxError: Unexpected token e in JSON at position 0 while parsing near 'export default __web...'
    at JSON.parse (<anonymous>)

My file is a valid JSON. For some reason, instead of displaying a static file Docusaurus seems to try to parse it...


Solution

  • I saw the same problem. My temporary solution is:

    • Change file name from .md to .mdx
    • Add this link to your json file
    <a target="_blank" href="/json/file.json" download="file.json">Download</a>