Convert knackhq data type instance to json friendly data.
328305
def convert_values(self, pydict):
        
        new_dict = dict()
        for key, value in pydict.items():
            try: # is it's BaseDataType Instance
                new_dict[key] = value._data
            except AttributeError:
                new_dict[key] = value
        return new_dict
259052
def _dict_to_json_pretty(d, sort_keys=True):
    '''
    
    '''
    return salt.utils.json.dumps(d, indent=4, separators=(',', ': '), sort_keys=sort_keys)
92514
def to_json(self, indent=None):
        """"""

        inputs = ParameterCollection(self.inputs)

        d = {
            'meta': {
                'name': self.name,
                'description': self.description
            },
            'inputs': [],
            'workflow': [],
            'outputs': [{'name': k, 'node': v} for k, v in six.iteritems(self.output_mapping)]
        }

        for parameter in self.inputs:
            input_info = {
                'name': parameter.name,
                'type': parameter.id
            }

            args, kwargs = parameter.serialize_args()
            args = list(args)
            args.pop(0)  # 'name' is already taken care of
            kwargs.pop('required', None)  # 'required' is assumed True for workflow inputs
            if args or kwargs:
                input_info['args'] = [args, kwargs]

            d['inputs'].append(input_info)

        for node in sorted(six.itervalues(self.nodes_by_id), key=lambda x: x.id):
            task_name = node.task.name
            if not task_name:
                raise ValueError('The task {0} does not have a name and therefore cannot be serialized.'.format(
                    node.task.__class__.__name__)
                )

            node_inputs = {}
            for input_name, (source, value) in six.iteritems(node.inputs):
                input_info = {'source': source}

                if source == 'input':
                    input_info['input'] = inputs.by_name[value].name
                else:
                    input_info['node'] = value

                node_inputs[input_name] = input_info

            d['workflow'].append({
                'id': node.id,
                'task': task_name,
                'inputs': node_inputs
            })

        return json.dumps(d, indent=indent)
154087
def json_data(self, instance, default=None):
        
        value = self.get(instance)
        return value or default
444362
def _record_from_json(value, field):
    """"""
    if _not_null(value, field):
        record = {}
        record_iter = zip(field.fields, value["f"])
        for subfield, cell in record_iter:
            converter = _CELLDATA_FROM_JSON[subfield.field_type]
            if subfield.mode == "REPEATED":
                value = [converter(item["v"], subfield) for item in cell["v"]]
            else:
                value = converter(cell["v"], subfield)
            record[subfield.name] = value
        return record
1325388
def to_json(data, compress=False):
    
    return json.compress(data) if compress else json.dumps(data)
1300718
def json(self, **kwargs):
        """"""
        encoding = detect_encoding(self.content[:4])
        value = self.content.decode(encoding)

        return simplejson.loads(value, **kwargs)
988600
def loadJson(self, data):
        """"""
        if not isinstance(data, dict):
            data = json.loads(data)
        self.__dict__.update(data)
        self.inflate() # restore objects from str values
        #if self.ports:  self._gotPorts = True
        return self
839764
def serialize_to_json(data, **kwargs):
    
    kwargs['cls'] = kwargs.get('cls', LazyJSONEncoder)

    return json.dumps(data, **kwargs)
1208210
def to_json(value, **kwargs):
        """"""
        if isinstance(value, HasProperties):
            return value.serialize(**kwargs)
        return value
1065602
def _datetime_to_json(value):
    """"""
    if isinstance(value, datetime.datetime):
        value = value.strftime(_RFC3339_MICROS_NO_ZULU)
    return value
488368
def to_json(self, sort_keys=False):
    
    d = self.to_json_dict()
    return json.dumps(d, sort_keys=sort_keys)
1146720
def dumps(self, sort_keys: bool = True, **kwargs) -> str:
        """"""
        return json.dumps(self.to_json(), sort_keys=sort_keys, **kwargs)
602824
def to_json(value):
    
    if type(value) in JSON_TYPES:
        return value
    elif hasattr(value, "to_json"):
        return value.to_json()
    elif isinstance(value, list) or isinstance(value, set) or \
            isinstance(value, deque) or isinstance(value, tuple):
        return [to_json(v) for v in value]
    elif isinstance(value, dict):
        return {str(k): to_json(v) for k, v in value.items()}
    else:
        raise TypeError("{0} is not json serializable.".format(type(value)))
860793
def json_data(self, instance, default=None):
        
        value = self.get(instance)
        if not value:
            return ""
        if callable(value):
            value = value()
        return api.to_iso_date(value, default=default)
1234919
def pretty_json(data):
    
    data = json.loads(data.decode('utf-8'))
    return json.dumps(data, indent=4, sort_keys=True)
8733
def dump_json(obj):
    """"""
    return simplejson.dumps(obj, ignore_nan=True, default=json_util.default)