← Back to release summary

JSON Modules

Category
JavaScript
Type
New or changed feature
Status
Enabled by default (Chrome 91)
Intent stage
Shipped

Summary

JSON modules allow statically importing JSON instead of consuming JSON dynamically through fetch(). JSON modules, like JavaSCript modules, are fetched using “cors” mode and strict MIME type checking. They also share the same module import syntax, for example: import data from "./resource.json”.

Motivation

There is not currently a way for developers to statically import JSON content as part of module graph instantiation. Currently developers are forced to consume JSON content dynamically through e.g. fetch(). See GitHub thread here for extensive discussion and many comments indicating support: https://github.com/whatwg/html/issues/4315. The StackOverflow thread here also contains comments highlighting the lack of this feature in ES6: https://stackoverflow.com/questions/34944099/how-to-import-a-json-file-in-ecmascript-6

Standards & signals

Docs: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/SyntheticModules/designDoc.md https://groups.google.com/a/chromium.org/d/topic/blink-dev/ojwkySW-bpQ/discussion

Explainers: https://github.com/whatwg/html/issues/4315

View on chromestatus.com