JsonDB provides a high performance, human readable data store that is primarily meant for system use but can be edited manually, or stored in a version control system such as Git.
JsonDB maps these tables into separate files - in this way each file contains a different type of data (eg. Things, Items, Links).
The system also keeps a number of backups in a ```backup``` folder.
Each time a file is updated, the current version will be moved to the ```backup``` folder and timestamped so that the system can retain the most recent files.
By default the last 5 copies of each file are retained.
When the system loads data from the file system, should it find that a file is corrupted it will attempt to open the most recent backup - it will try each backup in turn until a file is correctly read, or the number of files is reached.
To improve performance and reduce disk use all file writes are deferred for a few hundred milliseconds.
This ensures that if there are multiple updates of the database in a short time, the system will only write these updates to the file system after the group of updates completes.
If the system gets into a loop such that it is continually updating configuration information in the database, JsonDB will write a file every minute.
These timers can be configured by the user along with the number of backup files retained.
Data is stored in a "pretty" format to make it more human readable, and is sorted so ordering is not random (important when a version control system is used).
It is therefore editable by advanced users who might want to do a search and replace on item names etc.
It doesn't however ensure that the correct format is used - users wanting to edit a specific table are advised to first configure the system with the UI and then use the format generated by the UI as a template for subsequent additions and changes.
Most data stored in the database is written in a way that should be understandable by someone with good knowledge of the system.
As stated above, the files are only read during system startup - therefore if you change a file you will need to stop openHAB, make your changes and restart the system for the changes to take effect.
openHAB stores configuration information in JSON (JavaScript Object Notation) formatted (structured) text files located in the `OPENHAB_USERDATA/jsondb/` directory.
All configuration information regarding _**Items, Links, and Things**_ are defined via the User Interfaces (UI, REST) or via internal openHAB services.
The JSON DB does NOT store information for manually configured _**Items, Links, or Things**_, since these are already stored in files within the `OPENHAB_CONF` sub-directories (e.g. `/etc/openhab/items/`).
- Backup: Maintains a copy of your configurations in the `OPENHAB_USERDATA/jsondb/backup` directory
- Troubleshooting: Allows the user to interact with the configurations that were automatically generated via the UIs
- Advanced administration: Gives the possibility to manually define configuration parameters within the `*.json` files
## Storage Use
openHAB writes the `*.json` files every time a change is made via the User Interfaces.
openHAB _**reads the `*.json` files only once at startup**_. So, if you edit them manually, you should restart openHAB.
The system employs two write mechanisms to improve performance where there are multiple writes in a short time. When the service is closed, all open services are written to disk.
1._Maximum write delay_ (defaults to 30000 ms): Sets the maximum period the service will wait to write data in cases where changes are happening continually.
In this example, we will use the Network Binding (2.0) to Search for Things, add a new Thing to openHAB and then modify its parameters to check the information that is stored in the JsonDB.