Unserialize a JSON string representation of a topology
544400
def unserialize(jsonstr):
        '''
        
        '''
        topod = json.loads(jsonstr)
        G = json_graph.node_link_graph(topod)
        for n,ndict in G.nodes(data=True):
            if 'nodeobj' not in ndict or 'type' not in ndict:
                raise Exception("Required type information is not present in serialized node {} :{}".format(n, ndict))
            nobj = ndict['nodeobj']
            cls = eval(ndict['type'])
            ndict['nodeobj'] = cls(**dict(nobj))
        t = Topology(nxgraph=G)
        return t
500323
def to_json(self):
        """"""
        return {
            'network': self.network,
            'state': self.state,
            'nodes': self.node_indices,
            'cut': self.cut,
        }
756773
function unpackTx (tx) {
  const deserializedTx = TxBuilder.unpackTx(tx)
  console.log(JSON.stringify(deserializedTx, undefined, 2))
}
1212295
def json(self, json_string=None):
        
        if json_string is not None:
            return self.__init__(loads(json_string))
        dump = self
        if isinstance(self, HAR.log):
            dump = {"log": dump}
        return dumps(dump, default=lambda x: dict(x))
804049
def json_serial(obj):
    """"""
    if isinstance(obj, datetime):
        serial = obj.isoformat()
        return serial
    raise TypeError("Type not serializable")
1302303
function toJSON(unfilteredOptions) {
        const options = ghostBookshelf.Model.filterOptions(unfilteredOptions, 'toJSON');
        options.omitPivot = true;

        // CASE: get JSON of previous attrs
        if (options.previous) {
            const clonedModel = _.cloneDeep(this);
            clonedModel.attributes = this._previousAttributes;

            if (this.relationships) {
                this.relationships.forEach((relation) => {
                    if (this._previousRelations && this._previousRelations.hasOwnProperty(relation)) {
                        clonedModel.related(relation).models = this._previousRelations[relation].models;
                    }
                });
            }

            return proto.toJSON.call(clonedModel, options);
        }

        return proto.toJSON.call(this, options);
    }
718214
def from_json(cls, json_string):
        
        input_dict = json.loads(json_string)
        # convert index to tuple if required
        if input_dict['index'] and isinstance(input_dict['index'][0], list):
            input_dict['index'] = [tuple(x) for x in input_dict['index']]
        # convert index_name to tuple if required
        if isinstance(input_dict['meta_data']['index_name'], list):
            input_dict['meta_data']['index_name'] = tuple(input_dict['meta_data']['index_name'])
        data = input_dict['data'] if input_dict['data'] else None
        return cls(data=data, index=input_dict['index'], **input_dict['meta_data'])
1082790
function toJSON(d) {
    if (!_.isString(d)) {
        d = JSON.stringify(d);
    }

    return d;
}
7442
def __obj2json(self, obj):
        
        return json.dumps(obj, indent=self._indent, sort_keys=self._sort_keys)
358732
def fromJson(struct, attributes=None):
    ""
    if isinstance(struct, basestring):
        struct = json.loads(struct)
    indicative_attributes = {
        'x': Point,
        'wkid': SpatialReference,
        'paths': Polyline,
        'rings': Polygon,
        'points': Multipoint,
        'xmin': Envelope
    }
    # bbox string
    if isinstance(struct, basestring) and len(struct.split(',')) == 4:
        return Envelope(*map(float, struct.split(',')))
    # Look for telltale attributes in the dict
    if isinstance(struct, dict):
        for key, cls in indicative_attributes.iteritems():
            if key in struct:
                ret = cls.fromJson(dict((str(key), value)
                                   for (key, value) in struct.iteritems()))
                if attributes:
                    ret.attributes = dict((str(key.lower()), val) 
                                           for (key, val)
                                           in attributes.iteritems())
                return ret
    raise ValueError("Unconvertible to geometry")
599870
def to_json(self):
        """"""

        j = {}
        for p in self.properties:
            try:
                v = getattr(self, p)
            except AttributeError:
                continue
            if v is not None:
                if p == 't':
                    j[p] = getattr(self, p).isoformat()
                else:
                    j[p] = getattr(self, p)

        return json.dumps(j)
1118114
def serializable_dict(d):
    
    newd = {}
    for k in d.keys():
        if isinstance(d[k], type({})):
            newd[k] = serializable_dict(d[k])
            continue
        try:
            json.dumps({'k': d[k]})
            newd[k] = d[k]
        except:
            pass  # unserializable
    return newd
1067380
function deserialize(serialized){
    serialized.nodes.forEach(function (node){ addNode(node.id); });
    serialized.links.forEach(function (link){ addEdge(link.source, link.target, link.weight); });
    return graph;
  }
194941
function serialize(){
    var serialized = {
      nodes: nodes().map(function (id){
        return { id: id };
      }),
      links: []
    };

    serialized.nodes.forEach(function (node){
      var source = node.id;
      adjacent(source).forEach(function (target){
        serialized.links.push({
          source: source,
          target: target,
          weight: getEdgeWeight(source, target)
        });
      });
    });

    return serialized;
  }
57763
function toJSON() {
    var s = this;
    var values = Object.assign({}, s.schema);
    Object.keys(values).forEach(function (key) {
      var isFunc = iftype.isFunction(values[key]);

      if (isFunc) {
        delete values[key];
      }
    });
    return values;
  }
740678
def serialize_json_string(self, value):
        

        # Check if the value might be a json string
        if not isinstance(value, six.string_types):
            return value

        # Make sure it starts with a brace
        if not value.startswith('{') or value.startswith('['):
            return value

        # Try to load the string
        try:
            return json.loads(value)
        except:
            return value
384516
def to_json(self, obj, host=None, indent=None):
        """"""
        if indent:
            return json.dumps(deep_map(lambda o: self.encode(o, host), obj),
                              indent=indent)
        else:
            return json.dumps(deep_map(lambda o: self.encode(o, host), obj))