{"id":15032152,"url":"https://github.com/roger/serde-with-expand-env","last_synced_at":"2026-03-05T06:31:31.290Z","repository":{"id":57666795,"uuid":"227736318","full_name":"Roger/serde-with-expand-env","owner":"Roger","description":"Parse environment variables in serde crate using deserialize_with","archived":false,"fork":false,"pushed_at":"2023-03-27T05:01:16.000Z","size":14,"stargazers_count":9,"open_issues_count":3,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-09T10:19:16.436Z","etag":null,"topics":["rust","serde"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Roger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-12-13T02:14:05.000Z","updated_at":"2024-07-05T20:22:32.000Z","dependencies_parsed_at":"2024-01-18T04:08:12.511Z","dependency_job_id":"b40590db-ebce-4ef7-a58d-a095e8553f50","html_url":"https://github.com/Roger/serde-with-expand-env","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"d83f23c8f1af34d6297c4b0007f86a6b0f445676"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Roger%2Fserde-with-expand-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Roger%2Fserde-with-expand-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Roger%2Fserde-with-expand-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Roger%2Fserde-with-expand-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Roger","download_url":"https://codeload.github.com/Roger/serde-with-expand-env/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248132333,"owners_count":21053025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust","serde"],"created_at":"2024-09-24T20:17:31.874Z","updated_at":"2026-03-05T06:31:31.254Z","avatar_url":"https://github.com/Roger.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# serde-with-expand-env\n[![Build Status](https://travis-ci.org/Roger/serde-with-expand-env.svg?branch=master)](https://travis-ci.org/Roger/serde-with-expand-env) [![](http://meritbadge.herokuapp.com/serde-with-expand-env)](https://crates.io/crates/serde-with-expand-env) [![](https://docs.rs/serde-with-expand-env/badge.svg)](https://docs.rs/serde-with-expand-env) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)\n\nParse environment variables in [`serde`](https://github.com/serde-rs/serde) crate using `deserialize_with`.\n\n# Example:\n\n```rust\nuse std::env;\nuse serde_json;\nuse serde::Deserialize;\nuse serde_with_expand_env::with_expand_envs;\n\n#[derive(Deserialize, Debug)]\nstruct Test {\n    #[serde(deserialize_with=\"with_expand_envs\")]\n    number: usize,\n    #[serde(deserialize_with=\"with_expand_envs\")]\n    string: String,\n    #[serde(deserialize_with=\"with_expand_envs\")]\n    default: usize,\n}\n\nfn main() {\n    let serialized = r#\"{\"number\": \"$NUMBER\",\n                         \"string\": \"my string: $STRING\",\n                         \"default\": \"${DEFAULT:-42}\"\n                      }\"#;\n\n    // No envs set will fail with enviroment variable not found\n    assert_eq!(serde_json::from_str::\u003cTest\u003e(\u0026serialized).is_err(), true);\n\n    env::set_var(\"NUMBER\", \"42\");\n    env::set_var(\"STRING\", \"hacker\");\n    let deserialized: Test = serde_json::from_str(\u0026serialized).unwrap();\n\n    assert_eq!(deserialized.number, 42);\n    assert_eq!(deserialized.string, \"my string: hacker\");\n    assert_eq!(deserialized.default, 42);\n\n    env::set_var(\"DEFAULT\", \"4200\");\n    let deserialized: Test = serde_json::from_str(\u0026serialized).unwrap();\n    assert_eq!(deserialized.default, 4200);\n\n    // Invalid number\n    env::set_var(\"NUMBER\", \"cuarentaydos\");\n    env::set_var(\"STRING\", \"42\");\n    assert_eq!(serde_json::from_str::\u003cTest\u003e(\u0026serialized).is_err(), true);\n}\n```\n\nmore examples in [examples](examples/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froger%2Fserde-with-expand-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froger%2Fserde-with-expand-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froger%2Fserde-with-expand-env/lists"}