tauri-plugin-configurate can serialize any config to a string in JSON, YAML, or TOML format, and restore a config from such a string. This is useful for backups, sharing a config between users, or migrating a config from one format to another without changing the underlying provider.
exportAs
config.exportAs(format, keyringOpts?) loads the stored config and returns it serialized as a string.
// Export as JSON
const jsonString = await config.exportAs("json");
// Export as YAML
const yamlString = await config.exportAs("yml");
// Export as TOML
const tomlString = await config.exportAs("toml");
Including keyring fields in the export
By default, keyring fields are omitted from the exported string (they would appear as null). Pass KeyringOptions as the second argument to unlock keyring fields before serializing, so the export contains the actual secret values:
const KEYRING = { service: "my-app", account: "default" };
// Keyring fields are decrypted and included in the output
const yamlWithSecrets = await config.exportAs("yml", KEYRING);
An export that includes keyring fields contains plaintext secrets. Handle the resulting string with care — do not log it, store it unencrypted, or transmit it over an untrusted channel.
importFrom
config.importFrom(content, format, keyringOpts?) parses the provided string and replaces the current stored config with the parsed data.
// Import from a JSON string
await config.importFrom('{"theme": "dark", "language": "en"}', "json");
// Import from a YAML string
await config.importFrom("theme: dark\nlanguage: en\n", "yml");
// Import from a TOML string
await config.importFrom('theme = "dark"\nlanguage = "en"\n', "toml");
Importing configs with keyring fields
If the string to import contains plaintext secrets, pass KeyringOptions so the plugin routes those values to the OS keyring instead of writing them to disk:
const tomlWithSecrets = `
theme = "dark"
[database]
host = "db.example.com"
password = "imported-secret"
`;
// "password" is intercepted and stored in the OS keyring
await config.importFrom(tomlWithSecrets, "toml", KEYRING);
Omitting keyringOpts when the schema has keyring() fields causes the import to behave the same as any other write without keyring support — the secret value lands in the on-disk file rather than the OS keyring.
When to use export and import
Backups
Config sharing
Format migration
Export your config periodically and store the string somewhere safe (a database, a remote object store, a clipboard). Restore it with importFrom when needed. For automated in-process backups, see Rolling backups.// Create a backup
const backup = await config.exportAs("json", KEYRING);
await saveToRemote(backup);
// Restore from a backup
const backup = await loadFromRemote();
await config.importFrom(backup, "json", KEYRING);
Let users copy their settings as a YAML or TOML string and paste them into another machine or send them to support. Strip secrets by exporting without keyringOpts.// Safe to share — secrets are not included
const shareableYaml = await config.exportAs("yml");
await navigator.clipboard.writeText(shareableYaml);
If you want to switch a user’s storage from JsonProvider to TomlProvider, export from the JSON instance and import into the TOML instance.const jsonConfig = new Configurate({ ..., provider: JsonProvider() });
const tomlConfig = new Configurate({ ..., provider: TomlProvider() });
// Export from JSON, import into TOML
const exported = await jsonConfig.exportAs("json", KEYRING);
await tomlConfig.importFrom(exported, "json", KEYRING);
// Delete the old JSON file
await jsonConfig.delete(KEYRING);
| Format | Argument | Notes |
|---|
| JSON | "json" | Human-readable, supports null. Recommended for machine-generated exports. |
| YAML | "yml" | Human-readable, good for user-facing config sharing. |
| TOML | "toml" | Human-readable. TOML has no native null type — fields with null values are omitted. |
The export format is independent of the provider. You can export a config stored with BinaryProvider as "yml", or import a JSON string into a config backed by SqliteProvider.