javascript

Compress or minify JSON using Javascript

To compress or minify JSON using Javascript, you can use the below code.

var json_str = `[
    {
      "type": "people",
      "id": "30",
      "attributes": {
        "name": "John Deo",
        "age": 40,
        "gender": "male"
      }
    }
]`;

var minified_json = JSON.stringify(JSON.parse(json_str));
console.log(minified_json);
Was this helpful?