get http response in json format using url
@return json string with the response
518047
public CommandOutput<?, ?> getResponse(List<Command> cmds) throws RestApiProcessingException {
    String url = cmds.get(0).getParams().get(0);

    log.info("URL: " + url);
    String jsonStr = null;
    HttpRequestBase httpRequest = new HttpGet(url);
    addHeaders(httpRequest);
    HttpEntity httpEntity = null;
    HttpResponse httpResponse = null;
    try {
      httpResponse = this.httpClient.execute(httpRequest);
      StatusLine status = httpResponse.getStatusLine();
      httpEntity = httpResponse.getEntity();

      if (httpEntity != null) {
        jsonStr = EntityUtils.toString(httpEntity);
      }

      if (status.getStatusCode() >= 400) {
        log.info("Unable to get response using: " + url);
        JsonElement jsonRet = GSON.fromJson(jsonStr, JsonArray.class);
        throw new RestApiProcessingException(getFirstErrorMessage("Failed to retrieve response from", jsonRet));
      }
    } catch (Exception e) {
      throw new RestApiProcessingException("Failed to process rest api request; error - " + e.getMessage(), e);
    } finally {
      try {
        if (httpEntity != null) {
          EntityUtils.consume(httpEntity);
        }
        // httpResponse.close();
      } catch (Exception e) {
        throw new RestApiProcessingException("Failed to consume httpEntity; error - " + e.getMessage(), e);
      }
    }
    CommandOutput<RestApiCommand, String> output = new RestApiCommandOutput();
    output.put((RestApiCommand) cmds.get(0), jsonStr);
    return output;
  }
1019960
public function actionJson()
    {
        /** @var \yii\web\Response */
        $response = \Yii::$app->getResponse();
        
        if (!is_readable($this->module->swaggerPath)) {
            throw new NotFoundHttpException();
        }
        
        // Read source json file
        $json = file_get_contents($this->module->swaggerPath);
    
        // Do replacements
        if (is_array($this->module->swaggerReplace)) {
            foreach ($this->module->swaggerReplace as $find => $replace) {
                if (is_callable($replace)) {
                    $replaceText = call_user_func($replace);
                } else {
                    $replaceText = (string) $replace;
                }
                $json = mb_ereg_replace((string)$find, $replaceText, $json);
            }
        }
        
        // Override default response formatters
        // To avvoid json format modification
        $response->format = Response::FORMAT_RAW;
        $response->getHeaders()->set('Content-Type', 'application/json; charset=UTF-8');
        
        // Trigger events
        $event = new BeforeJsonEvent;
        $event->responseText = $json;
        $this->module->trigger(self::EVENT_BEFORE_JSON, $event);
        
        return $event->responseText;
    }
1179285
function getJSON(jsonUrl, done) {
    var parsedUrl = url.parse(jsonUrl);
    
    var options = {
        "host" : parsedUrl.hostname,
        "hostname": parsedUrl.hostname,
        "port" : parsedUrl.port || 80,
        "path" : parsedUrl.pathname,
        "method" : "GET",
        // "agent" : false,
    };
    
    debug && console.error("prepublish:getJSON('" + jsonUrl + "', done)");
    debug && console.error("options=" + util.inspect(options));
    var req = http.get(options, function (res) {
        debug && console.error("STATUS: " + res.statusCode);
        debug && console.error("HEADERS: " + JSON.stringify(res.headers));
        res.setEncoding('utf8');
        var data = '';
        res.on('data', function (chunk) {
            debug && console.error('getJSON: chunk="' + chunk + '"');
            data += chunk;
        });
        res.on('end', function() {
            debug && console.error('getJSON: end of request.');
            done(JSON.parse(data));
        });
    });

    req.on('error', function(error) {
        console.error("ERROR: " + error.message);
    });
}
1324983
public function toJson()
    {
        $json = null;
        if (!empty($this->toArray())) {
            $json = json_encode($this->toArray());
        }

        return $json;
    }
861383
public static function fetchJsonResponse(string $url): string
    {
        $response = self::getBrowser()->get($url, [
            'Accept' => 'application/json',
            'X-Internal-Request' => 'true'
        ]);

        self::handleFailure($response);

        return $response->getBody()->getContents();
    }
758616
public function jsonSerialize()
    {
        $serializer = $this->localSerializer ?? static::$serializer;
        if ($serializer) {
            return is_string($serializer)
                ? $this->rawFormat($serializer)
                : call_user_func($serializer, $this);
        }

        return $this->toJSON();
    }
588066
public String toJson() {
      try {
         Resource stringResource = Resources.fromString();
         write(stringResource);
         return stringResource.readToString().trim();
      } catch (IOException e) {
         throw Throwables.propagate(e);
      }
   }
930473
public function jsonResponse()
    {
        $user = Auth::getUser();

        //Change here whatever you need
        $ssoUser = new SSOUser();
        $ssoUser->id = $user->id;
        $ssoUser->name = $user->username;
        $ssoUser->email = $user->email;
        $ssoUser->roles = $user->roles;
        $ssoUser->profilepicture = "";

        $userInfo = $ssoUser->toArray();

        return VanillaSSO::WriteJsConnect($userInfo, $_GET, true);
    }
240631
public function toJson()
    {
        $json = array();

        $json['name'] = $this->getName();
        $json['privacy'] = $this->getPrivacy();
        //Parameters for PUT call (Room already exists)
        if ($this->getId()) {
            $json['is_archived'] = $this->isArchived();
            $json['is_guest_accessible'] = $this->isGuestAccessible();
            $json['topic'] = $this->getTopic();
            $json['owner'] = array('id' => $this->getOwner()->getId());
        } else { //Paramters for POST call
            $json['guest_access'] = $this->isGuestAccessible();
            if ($this->getOwner()) {
                $json['owner_user_id'] = $this->getOwner()->getId();
            }
        }
        return $json;
    }
1168812
private function format()
    {
        $request_uri = sprintf('%s %s', $this->request->getMethod(), $this->request->getBasePath().$this->request->getPathInfo());

        $ret = [
            'meta' => [
                'api_version'   => $this->getVersion(),
                'request'       => $request_uri,
                'response_time' => $this->responseTime,
                'http_code'     => $this->code,
                'error_type'    => $this->errorType,
                'error_message' => $this->errorMessage,
                'error_details' => $this->errorDetails,
                'charset'       => 'UTF-8',
            ],
            'response'          => $this->data,
        ];

        switch ($this->responseType) {
            case self::FORMAT_JSON:
            default:
                return new JsonResponse($ret);
            case self::FORMAT_YAML:
                if ($ret['response'] instanceof \stdClass) {
                    $ret['response'] = [];
                }

                $dumper = new Dumper();

                return new Response($dumper->dump($ret, 8));
            case self::FORMAT_JSONP:
                $response = new JsonResponse($ret);
                $response->setCallback(trim($this->request->get('callback')));

                return $response;
                break;
        }
    }
1248057
public function toJson()
    {
        $json = array();
        $json['id'] = $this->id;
        $json['url'] = $this->url;
        $json['pattern'] = $this->pattern;
        $json['event'] = $this->event;
        $json['name'] = $this->name;
        $json['links'] = $this->links;

        return $json;
    }
68842
public function getPayloadJSON()
    {
        $data = is_string($this->data) ? mb_convert_encoding($this->data, 'UTF-8') : $this->data;
        return json_encode($data);
    }
972063
def getJson(url):
    """"""
    site = urllib2.urlopen(url, timeout=300)
    return json.load(site)
112743
@GET
  @Path("/responses")
  @Produces("application/json")
  public String getResponses() throws UnknownHostException {
    Properties clientProps = getPropeSenderProps();

    String listenerIPAddress = clientProps.getProperty("listenerIPAddress");
    String listenerPort = clientProps.getProperty("listenerPort");
    String listenerReponsesURLPath = clientProps.getProperty("listenerReponsesURLPath", DEFAULT_RESPONSES_URL_PATH);

    String response = restGetCall("http://" + listenerIPAddress + ":" + listenerPort + listenerReponsesURLPath);

    return response;
  }
554950
public function get()
    {
        $result = null;
        switch ($this->format) {
            case 'nvp':
                $result = http_build_query($this->data);
                break;

            case 'json':
            default:
                $result = json_encode($this->data, JSON_PRETTY_PRINT);
                break;
        }

        return $result;
    }
504780
public String responseMessage() {
        try {
            connect();
            return connection.getResponseMessage();
        } catch (Exception e) {
            throw new HttpException("Failed URL: " + url, e);
        }
    }
511441
public function index(): JsonResponse
    {
        $config = $this->makeView('language-view', trans('HCCore::languages.title.list'))
            ->addFormSource('add-new', 'language')
            ->addDataTable($this->getDataTable())
            ->setPermissions(['search'])
            ->toArray();

        return $this->response->success('OK', $config);
    }