pub fn JsonEdit(
File: &Path,
Product: &str,
Id: &str,
Version: &str,
SidecarPath: Option<&str>,
) -> Result<bool, Error>Expand description
Dynamically modifies fields in a tauri.conf.json or tauri.conf.json5
file, including the sidecar path.
This function updates the following fields in the Tauri configuration:
version- The application versionproductName- The product name displayed to usersidentifier- The bundle identifier (reverse domain format)bundle.externalBin- Adds the sidecar binary path if provided
The function automatically detects and handles both JSON and JSON5 formats, ensuring compatibility with different Tauri configuration styles.
§Parameters
File- Path to the Tauri configuration fileProduct- The product name to set (displayed to users)Id- The bundle identifier to set (reverse domain format)Version- The version string to setSidecarPath- Optional path to the sidecar binary to bundle
§Returns
Returns a Result<bool> indicating:
Ok(true)- The file was modified and savedOk(false)- No changes were needed (all values already match)Err(BuildError)- An error occurred during modification
§Errors
BuildError::Io- If the file cannot be read or writtenBuildError::Json- If JSON parsing or serialization failsBuildError::Jsonfive- If JSON5 parsing failsBuildError::Utf- If UTF-8 conversion fails
§Behavior
- Only modifies fields that don’t match the specified values
- Creates nested structures (
bundle,externalBin) as needed - Writes output with tab indentation for human-readable formatting
- Logs configuration changes at INFO level
§JSON5 Support
JSON5 is a superset of JSON that allows:
- Trailing commas
- Unquoted property names
- Comments
- Multi-line strings
The function automatically detects JSON5 files by their .json5 extension
and uses the appropriate parser.
§Example
use crate::Maintain::Source::Build::JsonEdit;
let path = PathBuf::from("tauri.conf.json");
let modified = JsonEdit(
&path,
"Debug_Mountain",
"land.editor.binary.debug.mountain",
"1.0.0",
Some("Binary/node")
)?;