https://github.com/tjenkinson/rollup-plugin-json-parse
A rollup plugin that wraps compatible objects with JSON.parse() to improve performance.
https://github.com/tjenkinson/rollup-plugin-json-parse
json jsonparse optimisation performance rollup rollup-plugin
Last synced: 4 months ago
JSON representation
A rollup plugin that wraps compatible objects with JSON.parse() to improve performance.
- Host: GitHub
- URL: https://github.com/tjenkinson/rollup-plugin-json-parse
- Owner: tjenkinson
- License: mit
- Created: 2019-11-29T18:49:25.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-07-21T23:05:35.000Z (6 months ago)
- Last Synced: 2025-09-23T20:19:31.880Z (4 months ago)
- Topics: json, jsonparse, optimisation, performance, rollup, rollup-plugin
- Language: JavaScript
- Size: 1.13 MB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://badge.fury.io/js/rollup-plugin-json-parse)
# rollup-plugin-json-parse
A rollup plugin that wraps compatible objects with `JSON.parse()`.
Anything that is not compatible or would be less than 1024 characters, is left unchanged.
## Why?
It improves performance!
> Because the JSON grammar is much simpler than JavaScript’s grammar, JSON can be parsed more efficiently than JavaScript. This knowledge can be applied to improve start-up performance for web apps that ship large JSON-like configuration object literals (such as inline Redux stores).
See [this video on the chrome dev channel](https://youtu.be/ff4fgQxPaO0) and [the article on the V8 blog](https://v8.dev/blog/cost-of-javascript-2019#json) for more info.
[](https://youtu.be/ff4fgQxPaO0)
## Installation
```
npm install --save-dev rollup-plugin-json-parse
```
## Usage
```js
import { rollup } from 'rollup';
const rollupPluginJsonParse = require('rollup-plugin-json-parse');
export default {
input: 'main.js',
plugins: [
rollupPluginJsonParse({
minJSONStringSize: 1024 // default
})
]
});
```
## Example
The following assumes `minJSONStringSize` of `0` for demonstration purposes.
Input
```js
const a = {
prop1: () => {}, // can't be optimized
prop2: {
prop3: 2,
prop4: 'something',
['prop 5']: null
}
};
```
Output
```js
const a = {
prop1: () => {}, // can't be optimized
prop2: /*@__PURE__*/JSON.parse("{\"prop3\":2,\"prop4\":\"something\",\"prop 5\":null}")
};
```