def json_request(self, method, url, **kwargs):
        kwargs.setdefault('headers', {})
        kwargs['headers'].setdefault('Content-Type', 'application/json')
        kwargs['headers'].setdefault('Accept', 'application/json')

        if 'data' in kwargs:
            kwargs['data'] = jsonutils.dumps(kwargs['data'])

        resp = self._http_request(url, method, **kwargs)
        body = resp.content
        if 'application/json' in resp.headers.get('content-type', ''):
            try:
                body = resp.json()
            except ValueError:
                LOG.error('Could not decode response body as JSON')
        else:
            body = None

        return resp, body
def json_formatter(js):
    return jsonutils.dumps(js, indent=2, ensure_ascii=False)
from __future__ import print_function

import numbers
import os
import sys
import textwrap
import uuid

import prettytable
import yaml

from monasca_events import exc
from monasca_events.openstack.common import importutils
from monasca_events.openstack.common import jsonutils

supported_formats = {"json": lambda x: jsonutils.dumps(x, indent=2), "yaml": yaml.safe_dump}


# Decorator for cli-args
def arg(*args, **kwargs):
    def _decorator(func):
        # Because of the semantics of decorator composition if we just append
        # to the options list positional options will appear to be backwards.
        func.__dict__.setdefault("arguments", []).insert(0, (args, kwargs))
        return func

    return _decorator


def link_formatter(links):
    return "\n".join([l.get("href", "") for l in links or []])