Skip to content

Instantly share code, notes, and snippets.

@karthikax
Created January 11, 2021 10:16
Show Gist options
  • Save karthikax/d8e84b16c88dab2bfaf0dfca765c5c65 to your computer and use it in GitHub Desktop.
Save karthikax/d8e84b16c88dab2bfaf0dfca765c5c65 to your computer and use it in GitHub Desktop.
JSON file minify
const fs = require('fs');
const data = fs.readFileSync( process.argv[2], { encoding: 'utf8', flag: 'r' } );
const min = JSON.parse(data, (key, value) =>
typeof value === "number" ? Math.round(value * 100) / 100 : value
)
const minString = JSON.stringify( min )
const name = process.argv[2].split( '.' )
name.splice( -1, 0, 'min' )
fs.writeFileSync( name.join( '.' ), minString );
console.log( '\njson file with numbers minified successfully\n' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment