Serialise all the items in source_list to json
425347
def list_to_json(source_list):
    
    result = []
    for item in source_list:
        result.append(item.to_json())
    return result
1325388
def to_json(data, compress=False):
    
    return json.compress(data) if compress else json.dumps(data)
952393
def json_encode(obj, serialize):
    
    if hasattr(obj, 'to_dict'):
        return obj.to_dict(serialize=serialize)
    elif isinstance(obj, datetime):
        return obj.date().isoformat()
    elif isinstance(obj, date):
        return obj.isoformat()
    elif isinstance(obj, ProxyDict):
        return dict(obj)
    elif isinstance(obj, ProxyList):
        return list(obj)
    elif is_iterable_but_not_string(obj):
        return list(obj)
256809
def serialize(self, o):
        '''
        
        '''
        if isinstance(o, (list, tuple)):
            return [self.serialize(i) for i in o]
        if isinstance(o, dict):
            return {k: self.serialize(v) for k, v in o.items()}
        if isinstance(o, datetime):
            return o.isoformat()
        if isinstance(o, Result):
            return self.serialize(o.serialize())
        return o
226646
def _to_json(self):
        
        return dict(( (k, v) for k, v in self.__dict__.iteritems() if k != 'server'))
313738
def list_from_json(source_list_json):
    
    result = []
    if source_list_json == [] or source_list_json == None:
        return result
    for list_item in source_list_json:
        item = json.loads(list_item)
        try:
            if item['class_name'] == 'Departure':
                temp = Departure()
            elif item['class_name'] == 'Disruption':
                temp = Disruption()
            elif item['class_name'] == 'Station':
                temp = Station()
            elif item['class_name'] == 'Trip':
                temp = Trip()
            elif item['class_name'] == 'TripRemark':
                temp = TripRemark()
            elif item['class_name'] == 'TripStop':
                temp = TripStop()
            elif item['class_name'] == 'TripSubpart':
                temp = TripSubpart()
            else:
                print('Unrecognised Class ' + item['class_name'] + ', skipping')
                continue
            temp.from_json(list_item)
            result.append(temp)
        except KeyError:
            print('Unrecognised item with no class_name, skipping')
            continue
    return result
1362200
def serialize(self):
        """"""

        keys = self._all_keys()
        serdata = {}
        for fieldname, value in self._data.items():
            serdata[fieldname] = getattr(type(self), fieldname).python_to_cache(value)
        return json.dumps(serdata)
258872
def output_to_json(sources):
    """"""
    results = OrderedDict()
    for source in sources:
        if source.get_is_available():
            source.update()
            source_name = source.get_source_name()
            results[source_name] = source.get_sensors_summary()
    print(json.dumps(results, indent=4))
    sys.exit()
1071342
def serialize(self):
        
        import yaml
        output = {"metadata": self.metadata, "sources": {},
                  "name": self.name}
        for key, entry in self.items():
            output["sources"][key] = entry._captured_init_kwargs
        return yaml.dump(output)
212739
def to_json(*args)
      rows = []
      self.each_row do |row|
        rows.push(row.to_hash)
      end
      rows.to_json
    end
1161867
def dump_json(model, batch_len=200000, use_natural_keys=True, verbosity=1):
    
    model = get_model(model)

    N = model.objects.count()

    if verbosity > 0:
        widgets = [pb.Counter(), '/%d rows: ' % (N,), pb.Percentage(), ' ', pb.RotatingMarker(), ' ', pb.Bar(),' ', pb.ETA()]
        i, pbar = 0, pb.ProgressBar(widgets=widgets, maxval=N).start()

    JSONSerializer = serializers.get_serializer("json")
    jser = JSONSerializer()

    if verbosity > 0:
        pbar.update(0)
    for i, partial_qs in enumerate(util.generate_slices(model.objects.all(), batch_len=batch_len)):
        with open(model._meta.app_label.lower() + '--' + model._meta.object_name.lower() + '--%04d.json' % i, 'w') as fpout:
            if verbosity > 0:
                pbar.update(i*batch_len)
            jser.serialize(partial_qs, indent=1, stream=fpout, use_natural_keys=use_natural_keys)
    if verbosity > 0:
        pbar.finish()
1058881
def to_json_(self) -> str:
        
        try:
            renderer = pytablewriter.JsonTableWriter
            data = self._build_export(renderer)
            return data
        except Exception as e:
            self.err(e, "Can not convert data to json")
532744
def to_s
     data = [@name.concat(Array.new(32-@name.size, 0)), 
             @name_size, 
             @type, 
             @color, 
             @left, 
             @right, 
             @child, 
             @created,
             @modified, 
             @sector, 
             @size].flatten
      data.pack(PACKING)
    end
1328387
def to_json(self, *args, **kwargs):
        
        return json.dumps(self.serialized, *args, **kwargs)
1125143
def to_json(self, *, include=None):
        '''  '''
        json = dict()

        if include is None or 'id' in include or '*' in include:
            json['id'] = self.id

        if include is None or '_type' in include or '*' in include:
            json['_type'] = type(self).cls_key()

        def fieldfilter(fieldtuple):
            return \
                not fieldtuple[1].private and \
                not isinstance(fieldtuple[1], Relation) and (
                    include is None or fieldtuple[0] in include or '*' in include
                )

        json.update(dict(starmap(
            lambda fn, f: (fn, f.to_json(getattr(self, fn))),
            filter(
                fieldfilter,
                self.proxy
            )
        )))

        for requested_relation in parse_embed(include):
            relation_name, subfields = requested_relation

            if not hasattr(self.proxy, relation_name):
                continue

            relation = getattr(self.proxy, relation_name)

            if isinstance(relation, ForeignIdRelation):
                item = relation.get()

                if item is not None:
                    json[relation_name] = item.to_json(include=subfields)
                else:
                    json[relation_name] = None
            elif isinstance(relation, MultipleRelation):
                json[relation_name] = list(map(lambda o: o.to_json(include=subfields), relation.get()))

        return json
430404
def serialize(self, resources):
        """"""
        serialized = {
            'meta': {
                'sqlalchemy_jsonapi_version': '4.0.9'
            },
            'jsonapi': {
                'version': '1.0'
            }
        }
        # Determine multiple resources by checking for SQLAlchemy query count.
        if hasattr(resources, 'count'):
            serialized['data'] = []
            for resource in resources:
                serialized['data'].append(
                    self._render_resource(resource))
        else:
            serialized['data'] = self._render_resource(resources)

        return serialized
500354
def format_ret(return_set, as_json=False):
    
    ret_list = list()
    for item in return_set:
        d = {"ip": item}
        ret_list.append(d)

    if as_json:
        return json.dumps(ret_list)

    return ret_list