Search code examples
javascriptjqueryjsonyelp

Remove PrettyPrint Json


I have a problem with the Javascript -

 $.ajax({
 'url': message.action,
 'data': parameterMap,
 'cache': true,
 'dataType': 'jsonp',
 'jsonpCallback': 'cb',
 'success': function(data, textStats, XMLHttpRequest) {
   console.log(data);
   var output = prettyPrint(data);
   $("body").append(output);
  }
 });

This outputs the JSON using prettyprint. How do I output plain json (without prettyprint)? I tried

$("body").append(data)

Nothing showed up.

PS: I am using the Example Code provided by YELP.com . This is the link to the entire code - https://github.com/Yelp/yelp-api/blob/master/v2/js/search.html


Solution

  • For modern browsers that support natively JSON encoding/decoding you can use

    var output = JSON.stringify(data);
    

    For browsers that do not support it, you can find an implementation at http://www.json.org/js.html