From 814df605b66bd10b1ca3e6b480243fe81ececec3 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sun, 28 Feb 2016 09:22:44 -0800 Subject: [PATCH] add query string param to pretty-print JSON output --- controllers/Parse.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/controllers/Parse.php b/controllers/Parse.php index 4dc88a6..ad8bacb 100644 --- a/controllers/Parse.php +++ b/controllers/Parse.php @@ -7,6 +7,7 @@ use XRay\Formats; class Parse { public $http; + private $_pretty = false; public function __construct() { $this->http = new p3k\HTTP(); @@ -18,7 +19,9 @@ class Parse { $response->headers->set($k, $v); } $response->headers->set('Content-Type', 'application/json'); - $response->setContent(json_encode($params)); + $opts = JSON_UNESCAPED_SLASHES; + if($this->_pretty) $opts += JSON_PRETTY_PRINT; + $response->setContent(json_encode($params, $opts)."\n"); return $response; } @@ -37,6 +40,10 @@ class Parse { $this->http->max_redirects = (int)$request->get('max_redirects'); } + if($request->get('pretty')) { + $this->_pretty = true; + } + $url = $request->get('url'); if(!$url) {