Registry / serialization / json-loader

json-loader

JSON →
library0.5.7jsnpmunverified

A webpack loader for importing JSON files into JavaScript modules. Version 0.5.7 (latest, stable) is effectively deprecated because webpack >= v2.0.0 natively supports JSON imports. The loader is only useful for custom file extensions or legacy webpack v1 projects. It has minimal maintenance and no active development since 2017. Alternative: rely on webpack's built-in JSON support.

npm install json-loader
INSTALL
IMPORT
SIG · JSON-LOADER
J
json-loader
serializationjavascriptv0.5.7
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

json-loader (loader reference)
In webpack config: { test: /\.json$/, loader: 'json-loader' }
require('json-loader') directly in code (not a JS module)
In webpack v1, this loader is needed. Since webpack v2, JSON files work without this loader.
Inline usage
const json = require('json-loader!./file.json');
const json = require('json-loader')(require('./file.json'));
Inline usage is for webpack v1; in v2+ just require the JSON file directly.
Default import (ES modules)
import 'json-loader' (no direct use; configured in webpack)
import jsonLoader from 'json-loader'
json-loader is not a JavaScript module to import; it's a webpack loader referenced in config.

Shows how to configure json-loader in webpack v1 to import JSON files.

// webpack.config.js (webpack v1) module.exports = { entry: './app.js', output: { filename: 'bundle.js' }, module: { loaders: [ { test: /\.json$/, loader: 'json-loader' } ] } }; // app.js var data = require('./data.json'); console.log(data);
Debug
Known issues
deprecatedjson-loader is deprecated as webpack v2+ includes JSON support natively.
fix
For webpack v2+, remove json-loader and use built-in JSON handling. If you need a custom file extension, use a different loader.
affects: >=0.5.0
breakingThe loader previously used tab indentation in stringified JSON, which was changed to spaces for performance.
fix
Update to latest version (0.5.7). This change affects file size but not functionality.
affects: >=0.5.5
gotchaInline require('json-loader!./file.json') works in webpack v1 but not in v2+ where JSON is handled differently.
fix
For webpack v2+, do not use json-loader; just require the JSON file directly.
affects: >=0.5.0
Errors
Common errors & fixes
Module parse failed: Unexpected token (1:1) You may need an appropriate loader to handle this file type.
When webpack v1 is used without json-loader, it cannot parse JSON files.
fix
Add json-loader to webpack config with test: /\.json$/.
DeprecationWarning: json-loader is deprecated. Since webpack v2, JSON files are supported by default.
Using json-loader with webpack v2 or later triggers a deprecation warning.
fix
Remove json-loader from config and let webpack handle JSON natively.
Cannot find module 'json-loader'
json-loader is not installed or not in node_modules.
fix
Run: npm install --save-dev json-loader
Upgrade
Version history
0.5.7latest on npm
Audit
Dependencies
webpackrequiredwebpack peer dependency; loader requires webpack to function
Agent activity
13 hits · last 30 days
node
12
Amazon
1
Resources
json-loader — npm install json-loader · libregistry