A comprehensive solution for managing and updating file metadata across multiple datasets in Dataverse instances. This tool allows you to convert between JSON and CSV formats, manage multiple DOIs, and perform bulk metadata updates.
✨ Multi-Dataset Support: Handle multiple datasets with different DOIs in a single workflow
📊 CSV-Based Updates: Edit metadata in a familiar spreadsheet format
🔄 Bidirectional Conversion: Convert between JSON and CSV formats seamlessly
🚀 Bulk Operations: Update metadata for multiple files across datasets at once
🔐 API Integration: Direct integration with Dataverse API for secure updates
📋 Dry-Run Mode: Preview changes before applying them to your datasets
📦 Template System: Work with JSON templates organized in convenient folder structure
🎯 Tracking: Track update status and changes for each file
Update_FileMetadata_Dataverse_multipleDOIs/
├── utils.py # Utility functions for JSON/CSV operations
├── json_to_csv.py # Convert JSON files to CSV format
├── csv_to_json.py # Convert updated CSV back to JSON files
├── dataverse_api.py # Dataverse API interface for pushing updates
├── config.ini # Configuration file for settings
├── README.md # This file
├── WORKFLOW.md # Detailed workflow documentation
├── INSTALLATION.md # Installation and setup guide
├── data/
│ ├── json_templates/ # JSON template files for your datasets
│ │ ├── climate_data_2024.json
│ │ ├── genomic_data_species_a.json
│ │ └── survey_data_2024.json
│ ├── json_output/ # Generated JSON files (after CSV updates)
│ └── metadata.csv # Main metadata file for editing
├── backups/ # Automatic backups of original files
└── logs/ # Operation logs
# Clone or download the repository
cd Update_FileMetadata_Dataverse_multipleDOIs
# Install dependencies
pip install requests
# (Optional) Create a virtual environment first
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install requests# Convert all JSON templates to CSV
python json_to_csv.py --input-dir ./data/json_templates --output-csv ./data/metadata.csvThis creates a CSV with columns:
DOI- Dataset identifierdataset_name- Name of the datasetfile_id- Unique file identifierfile_label- File name/labelfile_description- Current descriptionfile_path- Current directory pathfile_size- File size in bytesoriginal_description- Original description (for reference)new_description- Update this column with new descriptionnew_file_path- Update this column with new file pathstatus- Track update status (default 'pending', after changed make it 'updated')
Open ./data/metadata.csv in your favorite spreadsheet editor (Excel, Google Sheets, etc.):
- Review the current metadata
- Edit the
new_descriptioncolumn with updated descriptions - Edit the
new_file_pathcolumn if file paths changed - Update the
statuscolumn as needed (as 'updated' instead of 'pending')
Example:
DOI | dataset_name | file_id | ... | original_description | new_description | status
doi:10.5061/dryad.example1 | Climate Data | file_001| ... | Old description | Updated desc | pending
# Convert your updated CSV back to JSON format
python csv_to_json.py --csv-file ./data/metadata.csv --output-dir ./data/json_outputThis generates JSON files in ./data/json_output/ organized by DOI.
# First, do a dry run to preview changes
python dataverse_api2.py --json-folder "Folder Path" --server-url "https://demo.borealisdata.ca/" --api-token "YOUR API TOKEN"
# Apply changes to Dataverse
python dataverse_api2.py --json-folder "Folder Path" --server-url "https://demo.borealisdata.ca/" --api-token "YOUR API TOKEN" --no-dry-runConvert one or more JSON files to CSV format:
# Convert all JSON files in directory
python json_to_csv.py \
--input-dir ./data/json_templates \
--output-csv ./data/metadata.csv
# Convert a single JSON file
python json_to_csv.py \
--json-file ./data/json_templates/climate_data_2024.json \
--output-csv ./data/single_dataset.csvConvert your edited CSV back to JSON files:
python csv_to_json.py \
--csv-file ./data/metadata.csv \
--output-dir ./data/json_output- Dataverse instance with API access
- Valid API token with appropriate permissions
- Dataverse server URL
python dataverse_api2.py \
--json-folder "Folder Path" \
--server-url "https://your-dataverse.org" \
--api-token "your-api-token"This shows what changes would be made without actually applying them.
python dataverse_api2.py \
--json-folder "Folder Path" \
--server-url "https://your-dataverse.org" \
--api-token "your-api-token" \
--no-dry-runexport DATAVERSE_SERVER_URL="https://your-dataverse.org"
export DATAVERSE_API_TOKEN="your-api-token"
python dataverse_api.py --csv-file ./data/metadata.csv --no-dry-runEach JSON file should follow this structure:
{
"datasetPersistentId": "doi:10.5061/dryad.example",
"datasetName": "Your Dataset Name",
"dataset": {
"version": 1,
"releaseTime": "2024-01-15T10:00:00Z"
},
"data": [
{
"id": "file_001",
"label": "filename.ext",
"description": "File description",
"directoryLabel": "folder_path",
"filesize": 1024576,
"dataType": "Text"
}
],
"lastUpdated": "2024-01-15T10:00:00Z"
}datasetPersistentId: The DOI of your dataset (required)datasetName: Human-readable name of the datasetdata: Array of file objectsid: Unique file identifier from Dataverselabel: File name or labeldescription: File descriptiondirectoryLabel: Directory path within the datasetfilesize: Size in bytesdataType: File type (Text, Spreadsheet, Document, Sequence, etc.)
After converting JSON to CSV, you'll see these working columns:
| Column | Purpose |
|---|---|
DOI |
Dataset identifier (read-only) |
dataset_name |
Dataset name (read-only) |
file_id |
File ID (read-only) |
file_label |
File name (read-only) |
file_description |
Current description (read-only) |
original_description |
Reference copy (read-only) |
new_description |
EDIT THIS - New file description |
new_file_path |
EDIT THIS - New directory path |
status |
Update status tracking |
pending- Changes ready to be appliedupdated- Changes successfully appliedno_changes- No updates needederror- Error during updateskipped- Update skipped
Edit config.ini to customize settings:
[dataverse]
server_url = https://your-dataverse.org
api_token = ${DATAVERSE_API_TOKEN}
[paths]
json_input_dir = ./data/json_templates
json_output_dir = ./data/json_output
csv_file = ./data/metadata.csv- Generate CSV from JSON files
- Edit
new_descriptioncolumn with better descriptions - Convert back to JSON
- Push to Dataverse
- Generate CSV from JSON files
- Edit
new_file_pathcolumn to reorganize files - Convert back to JSON
- Push to Dataverse
- Generate CSV from all JSON templates
- Edit multiple datasets in one spreadsheet
- Convert back to multiple JSON files
- Push all updates with single command
- Solution: Ensure JSON files are in
./data/json_templatesor specify correct path with--input-dir
- Solution: Ensure the CSV file path is correct and the file exists
- Solution: Check server URL and API token. Ensure server is accessible.
- Solution: API token is invalid. Generate new token in your Dataverse account settings.
- Always do a dry run first: Review changes before applying
- Keep backups: Original JSON files are preserved in
json_templatesdirectory - Test with one dataset: Before bulk updating, test with a single dataset
- Use version control: Track your CSV changes with Git
- Log API token: Set via environment variable, never hardcode
- Validate data: Review CSV data before converting to JSON
- Document changes: Update status column to track what was done
- Never commit API tokens: Use environment variables
- Protect CSV files: They contain file metadata which might be sensitive
- Use HTTPS: Ensure Dataverse connection is encrypted
- Limit permissions: Give API token only necessary permissions
- Audit logs: Enable logging to track all changes
load_json_file()- Load JSON filesave_json_file()- Save JSON fileload_csv_file()- Load CSV filesave_csv_file()- Save CSV fileextract_metadata_from_json()- Extract metadatavalidate_csv_row()- Validate CSV rowget_json_files_from_directory()- Get all JSON files from directory
json_to_csv_converter()- Main conversion function
csv_to_json_converter()- Main conversion function
DataverseAPI- Dataverse API client classpush_updates_from_csv()- Push updates to Dataverse
- Python 3.7+
- requests library (
pip install requests)
See LICENSE file for license information.
For issues or questions:
- Check the TROUBLESHOOTING section above
- Review WORKFLOW.md for detailed workflow documentation
- Check INSTALLATION.md for setup help
- Review log files in
./logsfor error details
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
- v1.0 - Initial release with multi-DOI bulk update support