Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jwccminify

AI Assisted Human Validated npm License: MIT

A lightweight JSON minifier that removes whitespace and comments from JWCC (JSON with Commas and Comments) or HuJSON (Human JSON).

  • Removes single-line comments (//)
  • Removes multi-line comments (/* */)
  • Removes whitespace (" \t\r\n")
  • Removes trailing commas before closing brackets and braces
  • No RegExp.
  • Zero dependencies.
  • Fault-tolerant: Invalid JSON is also parsable.

Usage

npm install jwccminify

ESM / CommonJS

import jwccminify from 'jwccminify';
// or
import { jwccminify } from 'jwccminify';
// or
const { jwccminify } = require('jwccminify');

const input = `{
  "name": "example", // This is a comment
  "value": 123, /* Multi-line
     comment */
}`;

const output = jwccminify(input);
console.log(output); // {"name":"example","value":123}
import { jwccstrip } from 'jwccminify';
// or
const { jwccstrip } = require('jwccminify');

const input = `{
  "name": "example", // This is a comment
  "value": 123, /* Multi-line
     comment */
}`;

const output = jwccstrip(input);
console.log(output);
// commas and comments were replaced with whitespace
// {
//   "name": "example",_____________________
//   "value": 123_______________
// ______________
// }

Browser UMD / ESM

<script src="./dist/jwccminify.umd.js"></script>
<script>
  const { jwccminify, jwccstrip } = JwccMinify;
</script>
<script type="module">
  const { jwccminify, jwccstrip } = await import('./dist/jwccminify.mjs');
</script>

License

MIT License

About

A lightweight JSON minifier that removes whitespace and comments from JWCC

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages