JSONModel
The ArchivesSpace system is concerned with managing a number of different archival record types. Each record can be expressed as a set of nested key/value pairs, and associated with each record type is a number of rules that describe what it means for a record of that type to be valid:
- some fields are mandatory, some optional
- some fields can only take certain types
- some fields can only take values from a constrained set
- some fields are dependent on other fields
- some record types can be nested within other record types
- some record types may be related to others through a hierarchy
- some record types form a relationship graph with other record types
The JSONModel class provides a common language for expressing these rules that all parts of the application can share. There is a JSONModel class instance for each type of record in the system, so:
is a class that knows how to take a hash of properties and make sure those properties conform to the specification of a Digital Object:
If it passes validation, a new JSONModel(:digital_object) instance is returned, which provides accessors for accessing its values, and facilities for round-tripping between JSON documents and regular Ruby hashes:
Much of the validation performed by JSONModel is provided by the JSON
schema definitions listed in the common/schemas
directory. JSON
schemas provide a standard way of declaring which properties a record
may and may not contain, along with their types and other
restrictions. ArchivesSpace uses these schemas to capture the
validation rules defining each record type in a declarative and
relatively self-documenting fashion.
JSONModel instances are the primary data interchange mechanism for the ArchivesSpace system: the API consumes and produces JSONModel instances (in JSON format), and much of the user interface’s life is spent turning forms into JSONModel instances and shipping them off to the backend.
JSONModel::Client — A high-level API for interacting with the ArchivesSpace backend
To save the need for a lot of HTTP request wrangling, ArchivesSpace ships with a module called JSONModel::Client that simplifies the common CRUD-style operations. Including this module just requires passing an additional parameter when initializing JSONModel:
If you’ll be working against a single repository, it’s convenient to set it as the default for subsequent actions:
Then, several additional JSONModel methods are available: