{"id":20302106,"url":"https://github.com/ifiokjr/package_json_schema","last_synced_at":"2025-08-30T15:24:07.452Z","repository":{"id":62444995,"uuid":"520154263","full_name":"ifiokjr/package_json_schema","owner":"ifiokjr","description":"A PackageJson struct for your rust code.","archived":false,"fork":false,"pushed_at":"2025-03-14T19:32:51.000Z","size":156,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-25T09:49:28.411Z","etag":null,"topics":["json","npm","package"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/package_json_schema","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ifiokjr.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-01T14:58:03.000Z","updated_at":"2025-03-14T19:29:16.000Z","dependencies_parsed_at":"2024-11-14T16:34:26.926Z","dependency_job_id":"3aa81c48-c3df-42dc-8485-9e2aba2cb529","html_url":"https://github.com/ifiokjr/package_json_schema","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"387e152108c306ed5e1004127974e4ec86f90315"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ifiokjr%2Fpackage_json_schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ifiokjr%2Fpackage_json_schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ifiokjr%2Fpackage_json_schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ifiokjr%2Fpackage_json_schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ifiokjr","download_url":"https://codeload.github.com/ifiokjr/package_json_schema/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248410259,"owners_count":21098772,"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":["json","npm","package"],"created_at":"2024-11-14T16:29:15.112Z","updated_at":"2025-04-11T13:37:04.342Z","avatar_url":"https://github.com/ifiokjr.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📦️ package_json_schema\n\n\u003cbr /\u003e\n\n\u003e Load a `package.json` file as a PackageJson `struct`.\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://crates.io/crates/package_json_schema\"\u003e\n    \u003cimg src=\"https://img.shields.io/crates/v/package_json_schema.svg\" alt=\"Crate\" title=\"Crate\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://docs.rs/package_json_schema\"\u003e\n    \u003cimg src=\"https://docs.rs/package_json_schema/badge.svg\" alt=\"Docs\" title=\"Docs\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/ifiokjr/package_json_schema/actions?query=workflow:ci\"\u003e\n    \u003cimg src=\"https://github.com/ifiokjr/package_json_schema/workflows/ci/badge.svg?branch=main\" alt=\"Continuous integration badge for github actions\" title=\"CI Badge\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://opensource.org/license/unlicense\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-Unlicence-blue.svg\" alt=\"License\" title=\"License\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codecov.io/github/ifiokjr/package_json_schema\" \u003e\n    \u003cimg src=\"https://codecov.io/github/ifiokjr/package_json_schema/graph/badge.svg?token=QCSIVQDOLT\"/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr /\u003e\n\n## Why?\n\nYou want to load a `package.json` file and interact with it as a struct.\n\n\u003cbr /\u003e\n\n## Installation\n\nAdd this line to the `[dependencies]` section of your `Cargo.toml`:\n\n```toml\npackage_json_schema = \"0.2\"\n```\n\nIf you would like to include validation then add the `validate` feature.\n\n```toml\npackage_json_schema = { version = \"0.2\", features = [\"validate\"] }\n```\n\nThis adds the `validator` crate as a dependency and adds the `.validate()` method to the `PackageJson` struct. The fields are validated according to the [JSON schema specification](https://json.schemastore.org/package.json).\n\n\u003cbr /\u003e\n\n## Usage\n\nThe following example shows how to load a `package.json` file and use it as a struct.\n\n```rust\nuse package_json_schema::PackageJson;\n\nlet contents = r###\"\n{\n  \"name\": \"my-package\",\n  \"version\": \"0.0.1\",\n  \"dependencies\": {\n    \"@sveltejs/kit\": \"1.0.0-next.396\"\n  },\n  \"peerDependencies\": {\n    \"aws-sdk\": \"2.1185.0\"\n  }\n}\n\"###;\n\nlet package_json = PackageJson::try_from(contents).unwrap();\nassert_eq!(package_json.name.unwrap(), \"my-package\");\nassert_eq!(package_json.version.unwrap(), \"0.0.1\");\n```\n\nThis crate leaves it to the user to load the `package.json` content from the filesystem. Here is an example of loading the file contents and parsing the contents into a struct.\n\n```rust\nuse std::fs::read_to_string;\nuse package_json_schema::PackageJson;\n\nlet contents = read_to_string(\"./tests/fixtures/1/package.json\").unwrap();\nlet package_json = PackageJson::try_from(contents).unwrap();\n\nassert_eq!(package_json.name.unwrap(), \"test\");\n```\n\nA `package.json` file can also be created from a builder.\n\n```rust\nuse package_json_schema::PackageJson;\nuse package_json_schema::AdditionalFields;\nuse package_json_schema::Person;\nuse indexmap::IndexMap;\n\nlet mut additional_fields: AdditionalFields = IndexMap::new();\nadditional_fields.insert(\"custom\".into(), \"value\".into());\n\nlet package_json = PackageJson::builder()\n  .name(\"awesome\")\n  .author(Person::String(\"Tester\".into()))\n  .other(additional_fields)\n  .build();\nlet string_value = package_json.try_to_string().unwrap();\n\nassert_eq!(\n  string_value,\n  r#\"{\"name\":\"awesome\",\"author\":\"Tester\",\"custom\":\"value\"}\"#\n);\n```\n\nTo validate the `package.json` fields, enable the `validate` feature.\n\n```toml\npackage_json_schema = { version = \"0.2.1\", features = [\"validate\"] }\n```\n\nAnd then use the `validate` method.\n\n```rust\nuse std::fs::read_to_string;\nuse package_json_schema::PackageJson;\n#[cfg(feature = \"validate\")]\nuse validator::Validate;\n\nlet contents = read_to_string(\"./tests/fixtures/1/package.json\").unwrap();\nlet package_json = PackageJson::try_from(contents).unwrap();\n\n#[cfg(feature = \"validate\")]\npackage_json.validate().unwrap();\n```\n\n\u003cbr /\u003e\n\n## Contributing\n\n[`devenv`](https://devenv.sh/) is used to provide a reproducible development environment for this project. Follow the [getting started instructions](https://devenv.sh/getting-started/).\n\nTo automatically load the environment you should [install direnv](https://devenv.sh/automatic-shell-activation/) and then load the `direnv`.\n\n```bash\n# The security mechanism didn't allow to load the `.envrc`.\n# Since we trust it, let's allow it execution.\ndirenv allow .\n```\n\nAt this point you should see the `nix` commands available in your terminal.\n\nRun the following commands to install all the required dependencies.\n\n```bash\ninstall:all\n```\n\nThis installs all cargo binaries locally so you don't need to worry about polluting your global namespace with required versions. The following scripts are added to your `PATH`.\n\n### `scripts`\n\n- build:all: Build all crates with all features activated.\n- build:docs: Build documentation site.\n- coverage:all: Generate a coverage report for the project\n- fix:all: Fix all fixable issues\n- fix:clippy: Fix all clippy issues\n- fix:format: Format the files with dprint\n- install:all: Install all packages.\n- lint:all: Lint the whole codebase and fail if any issues found.\n- lint:clippy: Check that lint rules are maintained for the entire project\n- lint:format: Check that formatting is correct for the project.\n- setup:ci: Setup the CI environment.\n- snapshot:update: Update all snapshots when running the test suite.\n- test:all: Run all tests for the project.\n- update:deps: Update dependencies.\n\n### Upgrading `devenv`\n\nIf you have an outdated version of `devenv` you can update it by running the following commands. If you have an easier way, please create a PR and I'll update these docs.\n\n```bash\nnix profile list # find the \u003cindex\u003e of the devenv package\nnix profile upgrade \u003cindex\u003e\n```\n\n### Editor Setup\n\nTo setup recommended configuration for your favorite editor run the following commands.\n\n```bash\nsetup:vscode # Setup vscode\n```\n\n## License\n\nUnlicense, see the [LICENSE](./license) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fifiokjr%2Fpackage_json_schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fifiokjr%2Fpackage_json_schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fifiokjr%2Fpackage_json_schema/lists"}