Minify JSON

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

Another way to minify JSON is to use the npm package.


npm install -g json-minify


Having a test-data.json file

  "friends": [
      "id": 0,
      "name": "Amparo Henry"
      "id": 1,
      "name": "Stone Ferguson"
      "id": 2,
      "name": "Cheryl Rocha"

Defaults to stdout

tan@omega:~$ json-minify test-data.json
{"friends":[{"id":0,"name":"Amparo Henry"},{"id":1,"name":"Stone Ferguson"},{"id":2,"name":"Cheryl Rocha"}]}

Write to new file

json-minify test-data.json > minified.json

Or use it as pipe

tan@omega:~$ curl -s http://elasticsearch:9200 | json-minify
{"name":"dev","cluster_name":"fo-test","cluster_uuid":"sE_HoGSZRKyhGHN9lk2gSA","version":{"number":"5.4.3","build_hash":"eed30a8","build_date":"2017-06-22T00:34:03.743Z","build_snapshot":false,"lucene_version":"6.5.1"},"tagline":"You Know, for Search"}
Please remember the terms for blog comments.