Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove white space in Json

How can I remove white space in the following code block and store in a javascript variable?

This is original format

{ "info":"First Json",
  "description":"Official Website",
  "timestamp":"1337936081",
   "rates":{
            "USD":"840", 
            "CHF":"1319", 
            "BDT":"298",
            } 
}    

This is the format I want

{"info":"Central Bank of Myanmar","description":"Official Website of Central Bank of Myanmar","timestamp":"1337936081","rates":{"USD":"840","CHF":"1319","BDT":"298","SGD":"632","JPY":"1053","GBP":"887","AUD":"759"}}     
like image 779
Chit Min Thu Avatar asked Dec 20 '22 09:12

Chit Min Thu


1 Answers

var jsonWithWhitespaceRemoved = JSON.stringify(JSON.parse(variableWithJsonWhitespace))
like image 125
Rovak Avatar answered Dec 24 '22 01:12

Rovak