Module Reference¶
jsonobj¶
Wrapper module to provide a simple property accessor for JSON objects.
-
jsonobj.dump(obj, fp, **kwargs)[source]¶ Serialize obj as a JSON formatted stream to fp with the same interface as the standard
json.dump().
-
jsonobj.dumps(obj, **kwargs)[source]¶ Serialize obj to a JSON formatted
strwith the same interface as the standardjson.dumps().
-
jsonobj.load(fp, **kwargs)[source]¶ Deserialize fp to a wrapped JSON object with the same interface as the standard
json.load().
-
jsonobj.loads(s, **kwargs)[source]¶ Deserialize s to a wrapped JSON object with the same interface as the standard
json.loads().
-
jsonobj.wrap(value)[source]¶ Wrap a standard
dictorlistto aJSONobjorJSONarray.>>> wrap({'key': 'value'}) JSONobj({'key': 'value'}) >>> wrap(['foo', 'bar']) JSONarray(['foo', 'bar']) >>> wrap(('foo', 'bar')) JSONarray(('foo', 'bar'))
-
jsonobj.unwrap(value)[source]¶ Unwrap a
JSONobjorJSONarrayto a standarddictorlist.>>> unwrap(JSONobj({'key': 'value'})) {'key': 'value'} >>> unwrap(JSONarray(['foo', 'bar'])) ['foo', 'bar'] >>> unwrap(JSONarray(('foo', 'bar'))) ('foo', 'bar')
-
class
jsonobj.JSONobj(jsondict={})[source]¶ Wrapper class of a JSON object for providing pseudo-attribute access to JSON object properties.
Parameters: jsondict ( dict) – Adictrepresenting a JSON object.>>> obj = JSONobj({'key': 'value'}) >>> obj.key 'value' >>> obj.foo = 'bar' >>> 'foo' in obj True >>> obj.foo = 'fiz' >>> obj.dict {'key': 'value', 'foo': 'fiz'} >>> del obj.foo >>> str(obj) '{"key": "value"}'
-
class
jsonobj.JSONarray(jsonseq=[])[source]¶ Wrapper class of a JSON array for supporting
JSONobj.Parameters: jsonseq ( sequence) – Alistortuplerepresenting a JSON array.>>> array = JSONarray([{'key': 'value'}]) >>> array[0].key 'value' >>> array.append(JSONobj({'foo': 'bar'})) >>> array.seq [{'key': 'value'}, {'foo': 'bar'}] >>> for e in array: ... e JSONobj({'key': 'value'}) JSONobj({'foo': 'bar'})
-
seq¶ The raw sequence.
Type: sequence
-