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 str with the same interface as the standard json.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 dict or list to a JSONobj or JSONarray.

>>> wrap({'key': 'value'})
JSONobj({'key': 'value'})
>>> wrap(['foo', 'bar'])
JSONarray(['foo', 'bar'])
>>> wrap(('foo', 'bar'))
JSONarray(('foo', 'bar'))
jsonobj.unwrap(value)[source]

Unwrap a JSONobj or JSONarray to a standard dict or list.

>>> 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) – A dict representing 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"}'
dict

The raw dict.

Type:dict
__getattr__(name)[source]

Return the value of the name property.

__setattr__(name, value)[source]

Set the name property to value.

class jsonobj.JSONarray(jsonseq=[])[source]

Wrapper class of a JSON array for supporting JSONobj.

Parameters:jsonseq (sequence) – A list or tuple representing 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