jams.JObject
- class jams.JObject(**kwargs)[source]
Bases:
objectDict-like object for JSON Serialization.
This object behaves like a dictionary to allow init-level attribute names, seamless JSON-serialization, and double-star style unpacking (** obj).
By setting the
typeattribute to a defined schema entry, only the fields allowed by the schema are permitted as attributes.- __init__(**kwargs)[source]
Construct a new JObject
- Parameters:
- **kwargs
Each keyword argument becomes an attribute with the specified value
Examples
>>> J = jams.JObject(foo=5) >>> J.foo 5 >>> dict(J) {'foo': 5}
Attributes
The type (class name) of a derived JObject type
Methods
__init__(**kwargs)Construct a new JObject
dumps(**kwargs)Serialize the JObject to a string.
keys()Return a list of the attributes of the object.
loads(string)De-serialize a JObject
search(**kwargs)Query this object (and its descendants).
update(**kwargs)Update the attributes of a JObject.
validate([strict])Validate a JObject against its schema
- dumps(**kwargs)[source]
Serialize the JObject to a string.
- Parameters:
- **kwargs
Keyword arguments to json.dumps
- Returns:
- object_strstr
Serialized JObject
See also
Examples
>>> J = jams.JObject(foo=5, bar='baz') >>> J.dumps() '{"foo": 5, "bar": "baz"}'
- keys()[source]
Return a list of the attributes of the object.
- Returns:
- keyslist
The attributes of the object
Examples
>>> J = jams.JObject(foo=5, bar='baz') >>> J.keys() ['foo', 'bar']
- classmethod loads(string)[source]
De-serialize a JObject
- Parameters:
- stringstr
A serialized (JSON string) JObject
- Returns:
- JJObject
The input string reconstructed as a JObject
See also
Examples
>>> J = jams.JObject(foo=5, bar='baz') >>> J.dumps() '{"foo": 5, "bar": "baz"}' >>> jams.JObject.loads(J.dumps()) <JObject foo, bar>
- search(**kwargs)[source]
Query this object (and its descendants).
- Parameters:
- **kwargs
Each (key, value) pair encodes a search field in key and a target value in value.
key must be a string, and should correspond to a property in the JAMS object hierarchy, e.g., ‘Annotation.namespace` or
emailvalue must be either an object (tested for equality), a string describing a search pattern (regular expression), or a lambda function which evaluates to True if the candidate object matches the search criteria and False otherwise.
- Returns:
- matchbool
True if any of the search keys match the specified value, False otherwise, or if the search keys do not exist within the object.
Examples
>>> J = jams.JObject(foo=5, needle='quick brown fox') >>> J.search(needle='.*brown.*') True >>> J.search(needle='.*orange.*') False >>> J.search(badger='.*brown.*') False >>> J.search(foo=5) True >>> J.search(foo=10) False >>> J.search(foo=lambda x: x < 10) True >>> J.search(foo=lambda x: x > 10) False
- property type
The type (class name) of a derived JObject type