You can parse the JSON and then immediately re-serialize the parsed object:

var myJson = `{
    "name": "sample name",
    "product": "sample product",
    "address": "sample address" 
}`;

// 'Minifying' the JSON string is most easily achieved using the built-in
// functions in the JSON namespace:
var minified = JSON.stringify(JSON.parse(myJson));

console.log(minified);

You'll have to perform the minification server-side to get an improvement in response size. I suppose most languages support an equivalent to the above snippet. For example, in php one might write this (if your server runs php, of course):

$myJson = '{
    "name": "sample name",
    "product": "sample product",
    "address": "sample address" 
}';

$minified = json_encode(json_decode($myJson));
Answer from JJWesterkamp on Stack Overflow
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ jsonminify
jsonminify - npm
December 18, 2021 - JSON.minify() minifies blocks of JSON-like content into valid JSON by removing all whitespace *and* comments.. Latest version: 0.4.2, last published: 4 years ago. Start using jsonminify in your project by running `npm i jsonminify`. There are ...
      ยป npm install jsonminify
    
Published ย  Dec 18, 2021
Version ย  0.4.2
Author ย  Kei Funagayama
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ node-json-minify
node-json-minify - npm
JSON-minify minifies blocks of JSON-like content into valid JSON by removing all whitespace and JS-style comments (single-line // and multiline /* ..
      ยป npm install node-json-minify
    
Published ย  Dec 22, 2021
Version ย  3.0.0
Author ย  Kyle Simpson
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ json-minify
json-minify - npm
A commandline utility to minify JSON files. Latest version: 1.0.0, last published: 14 years ago. Start using json-minify in your project by running `npm i json-minify`. There are 3 other projects in the npm registry using json-minify.
      ยป npm install json-minify
    
Published ย  Jan 22, 2012
Version ย  1.0.0
Author ย  AJ ONeal
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ minify
minify - npm
2 weeks ago - Minify walking up parent directories to locate and read itโ€™s configuration file .minify.json.
      ยป npm install minify
    
Published ย  Mar 04, 2026
Version ย  15.2.0
Author ย  coderaiser
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ minify-json
minify-json - npm
September 3, 2017 - Minify JSON & GeoJSON Files. Latest version: 1.0.0, last published: 9 years ago. Start using minify-json in your project by running `npm i minify-json`. There are 0 other projects in the npm registry using minify-json.
      ยป npm install minify-json
    
Published ย  Mar 09, 2017
Version ย  1.0.0
๐ŸŒ
GitHub
github.com โ€บ aminya โ€บ minijson
GitHub - aminya/minijson: Minify JSON files fast! Supports Comments. Uses D, C, and AVX2 and SSE4_1 SIMD.
Minify JSON files blazing fast, removing comments/whitespace. Uses D, C, and AVX2 and SSE4_1 SIMD. 4180 times faster than jsonminify! Npm (Nodejs) npm install @aminya/minijson ยท Dub (D) git submodule update --init --recursive dub build --config=library --build=release-nobounds --compiler=ldc2 # or dub build --config=executable --build=release-nobounds --compiler=ldc2 ยท
Author ย  aminya
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ @types โ€บ jsonminify
@types/jsonminify - npm
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jsonminify. declare global { interface JSON { /** * minifies blocks of JSON-like content into valid JSON by removing all whitespace and comments.
      ยป npm install @types/jsonminify
    
๐ŸŒ
Cloudsmith
cloudsmith.com โ€บ navigator โ€บ npm โ€บ node-json-minify
node-json-minify (3.0.0) - npm Package Quality | Cloudsmith Navigator
$npm install node-json-minify ยท /Processing... โœ“Done ยท Start your free trial ยท 3.0.0 ยท Stable version ยท 4years ago ยท Released ยท Loading Version Data ยท NPM on Cloudsmith ยท Learn more about NPM on Cloudsmith ยท
Find elsewhere
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ @node-minify โ€บ jsonminify
@node-minify/jsonminify - npm
November 12, 2024 - import { minify } from '@node-minify/core'; import { jsonMinify } from '@node-minify/jsonminify'; await minify({ compressor: jsonMinify, input: 'foo.json', output: 'bar.json' });
      ยป npm install @node-minify/jsonminify
    
Published ย  Jan 22, 2026
Version ย  10.4.0
Author ย  Rodolphe Stoclin
๐ŸŒ
npm
npmjs.com โ€บ search
keywords:minify json - npm search
Minifies blocks of JSON-like content into valid JSON by removing all whitespace and comments.
๐ŸŒ
GitHub
github.com โ€บ Josee9988 โ€บ MinifyAllCli
GitHub - Josee9988/MinifyAllCli: ๐Ÿ“ฆ A lightweight, simple and easy npm tool to ๐—บ๐—ถ๐—ป๐—ถ๐—ณ๐˜† JSON/C, HTML and CSS! Also known as MinifyAll core! โญ Usable as ๐‘ช๐‘ณ๐‘ฐ tool or ๐’Š๐’Ž๐’‘๐’๐’“๐’•๐’‚๐’ƒ๐’๐’† in TS/JS as a ๐‘ด๐‘ถ๐‘ซ๐‘ผ๐‘ณ๐‘ฌ ๐Ÿฅฐ
๐Ÿ“ฆ A lightweight, simple and easy npm tool to ๐—บ๐—ถ๐—ถ๐—ณ๐˜† JSON/C, HTML and CSS! Also known as MinifyAll core! โญ Usable as ๐‘ช๐‘ณ๐‘ฐ tool or ๐’Š๐’Ž๐’‘๐’๐’“๐’•๐’‚๐’ƒ๐’๐’† in TS/JS as a ๐‘ด๐‘ถ๐‘ซ๐‘ผ๐‘ณ๐‘ฌ ๐Ÿฅฐ - Josee9988/MinifyAllCli
Starred by 25 users
Forked by 5 users
Languages ย  TypeScript 94.6% | Shell 3.2%
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ json-minifier
json-minifier - npm
March 13, 2018 - A two-way JSON minifier to reduce JSON size and amount of data transferred on clients. Can also act as an obfuscator.. Latest version: 0.0.3, last published: 8 years ago. Start using json-minifier in your project by running `npm i json-minifier`. ...
      ยป npm install json-minifier
    
Published ย  Mar 13, 2018
Version ย  0.0.3
Author ย  Dial Once
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ minify-inline-json
minify-inline-json - npm
September 25, 2023 - Latest version: 1.1.11, last published: 2 years ago. Start using minify-inline-json in your project by running `npm i minify-inline-json`. There are 1 other projects in the npm registry using minify-inline-json.
      ยป npm install minify-inline-json
    
Published ย  Sep 25, 2023
Version ย  1.1.11
Author ย  HP Dietz
๐ŸŒ
GitHub
gist.github.com โ€บ getify โ€บ 5935939
Example of how to use JSON.minify() to pre-process your JSON strings and remove comments (and whitespace) before parsing. ยท GitHub
Example of how to use JSON.minify() to pre-process your JSON strings and remove comments (and whitespace) before parsing. - data.json
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ grunt-json-minify
grunt-json-minify - npm
JSON minification plugin without concatination.. Latest version: 1.1.0, last published: 9 years ago. Start using grunt-json-minify in your project by running `npm i grunt-json-minify`. There are 4 other projects in the npm registry using grunt-json-minify.
      ยป npm install grunt-json-minify
    
Published ย  Jun 29, 2016
Version ย  1.1.0
Author ย  Malte Legenhausen
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ gulp-json-minify
gulp-json-minify
July 20, 2023 - var gulp = require('gulp'), util = require('gulp-util'), jsonMinify = require('gulp-json-minify'); gulp.task('json:minify', function() { return gulp.src('src/data/spritesheet/*.json') .pipe(jsonMinify()) .pipe(gulp.dest('build/production')) .on('error', util.log); });
      ยป npm install gulp-json-minify
    
Published ย  Jul 20, 2023
Version ย  1.2.3
Author ย  Csaba Tuncsik
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ gulp-jsonminify
gulp-jsonminify - npm
January 8, 2018 - Minifies blocks of JSON-like content into valid JSON by removing all whitespace and comments, using JSON.minify.
      ยป npm install gulp-jsonminify
    
Published ย  Jan 08, 2018
Version ย  1.1.0
Author ย  tcarlsen
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ rehype-minify-json-script
rehype-minify-json-script - npm
September 27, 2024 - This package is a plugin that can minify the contents of JSON <script>s: <script> elements with (currently) a type of application/ld+json. You can use this plugin when you want to improve the size of HTML documents.
      ยป npm install rehype-minify-json-script
    
Published ย  Sep 27, 2024
Version ย  4.0.1
Author ย  Titus Wormer
๐ŸŒ
jsDelivr
jsdelivr.com โ€บ package โ€บ npm โ€บ json-minify
json-minify CDN by jsDelivr - A CDN for npm and GitHub
January 22, 2012 - A free, fast, and reliable CDN for json-minify. A commandline utility to minify JSON files
Published ย  Jan 22, 2012