{"id":28959507,"url":"https://github.com/naomijub/serde_json_shape","last_synced_at":"2025-08-01T10:35:43.990Z","repository":{"id":298972272,"uuid":"1001050668","full_name":"naomijub/serde_json_shape","owner":"naomijub","description":"Crate to help define the shape of a json file","archived":false,"fork":false,"pushed_at":"2025-07-08T22:57:47.000Z","size":75,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-21T23:47:29.828Z","etag":null,"topics":["format","json","shape"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/json_shape","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/naomijub.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-12T18:28:55.000Z","updated_at":"2025-07-08T22:57:50.000Z","dependencies_parsed_at":"2025-06-13T22:39:45.308Z","dependency_job_id":"812660b9-3e49-495f-b050-feadf4c3721b","html_url":"https://github.com/naomijub/serde_json_shape","commit_stats":null,"previous_names":["naomijub/serde_json_shape"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/naomijub/serde_json_shape","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naomijub%2Fserde_json_shape","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naomijub%2Fserde_json_shape/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naomijub%2Fserde_json_shape/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naomijub%2Fserde_json_shape/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naomijub","download_url":"https://codeload.github.com/naomijub/serde_json_shape/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naomijub%2Fserde_json_shape/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268207574,"owners_count":24213011,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["format","json","shape"],"created_at":"2025-06-24T00:01:54.622Z","updated_at":"2025-08-01T10:35:43.968Z","avatar_url":"https://github.com/naomijub.png","language":"Rust","readme":"\n[![Latest Version](https://img.shields.io/crates/v/json_shape)](https://crates.io/crates/json_shape)\n[![License:Apache](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![Build Status](https://github.com/naomijub/serde_json_shape/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/naomijub/serde_json_shape/actions/workflows/rust.yml)\n[![Coverage Status](https://coveralls.io/repos/github/naomijub/serde_json_shape/badge.svg?branch=main)](https://coveralls.io/github/naomijub/serde_json_shape?branch=main)\n\n# JSON_Shape\n\nThis libraries is not intended to serialize a JSON into a value representation like [`serde_json`](https://crates.io/crates/serde_json) does but to represent that types of data that a json or multiple jsons have:\n\n```json\n{\n    \"str\": \"this is a string\",\n    \"number\": 123.456,\n    \"array\": [1, 2, 3, 4],\n    \"bool_true\": true,\n    \"bool_false\": false,\n    \"nil\": null,\n    \"tuple\": [123, \"string\", true],\n    \"map\": {\n        \"a\": \"b\",\n        \"c\": 123\n    },\n    \"array of maps\": [\n        {\n            \"a\": \"b\",\n            \"c\": 123\n        },\n        {\n            \"a\": \"b\",\n            \"b\": true\n        }\n    ]\n}\n```\n\nWill be parsed as:\n\n```ru\nObject{\n    array: Array\u003cNumber\u003e,\n    \"array of maps\": Array\u003cObject{\n        a: String, \n        b: Option\u003cBoolean\u003e, \n        c: Option\u003cNumber\u003e\n    }\u003e, \n    bool_false: Boolean, \n    bool_true: Boolean, \n    map: Object{\n        a: String, \n        c: Number\n    }, \n    nil: Null, \n    number: Number, \n    str: String,\n    tuple: Tuple(Boolean, Number, String)\n}\n```\n\n### General rules when merging two [`JsonShape`]:\n- `T + Null = Option\u003cT\u003e`\n- `T + U = OneOf[T | U]`\n- `T + Option\u003cU\u003e = OneOf[T | U | Null]`\n- `Tuple(U, T, V) + Tuple(U, T, Null) = Tuple(U, T, Option\u003cV\u003e)`\n- `Array\u003cT\u003e + Array\u003cU\u003e =\u003e Array\u003cOneOf[T | U]\u003e`\n- `Tuple(U, T, V) + Array\u003cU\u003e = Array\u003cOneOf[T | U | V]\u003e`\n- `Object{key: Number, \"key space\": Bool} +  Object{key: String, \"key_special_char?\": String} =\u003e Object{key: OneOf[Number | String], \"key space\": Option\u003cBool\u003e, \"key_special_char?\": Option\u003cString\u003e }`\n- `OneOf[T | U] + OneOf[V | X] = OneOf[T | U | V | X]`\n- `OneOf[T | U] + Option\u003cU\u003e = OneOf[T | U | Null]`\n\n\u003e ### Usage Warning\n\u003e\n\u003e This library does not conform to Swagger or JsonSchema specifications, as they are signiticantly more complex than the intended usage for this library.\n\n\n## Installation\nRun the following Cargo command in your project directory:\n\n```shell\n$ cargo add json_shape\n```\n\nOr add the following line to your Cargo.toml:\n\n```toml\n[dependencies]\njson_shape = \"0.5\"\n```\n\n## Usage \n\n### From `String`s\n\n```rust\nuse json_shape::JsonShape;\nuse std::str::FromStr;\n\nlet source = r#\"{\n        \"str\": \"this is a string\",\n        \"number\": 123.456,\n        \"bool_true\": true,\n        \"bool_false\": false,\n        \"nil\": null,\n        \"tuple\": [123, \"string\", true],\n        \"map\": {\n          \"a\": \"b\",\n          \"c\": 123\n        },\n        \"array of maps\": [\n            {\n                \"a\": \"b\",\n                \"c\": 123\n            },\n            {\n                \"a\": \"b\",\n                \"b\": true\n            }\n        ]\n    }\"#;\n\nlet json_shape = JsonShape::from_str(source).unwrap();\n```\n\n* If multiple `JSON` sources are available, you may use [`JsonShape::from_sources`](https://docs.rs/json_shape/latest/json_shape/enum.JsonShape.html#method.from_sources), which expects a list of Json strings.\n\n### From `serde_json::Value`\n\n```rust\nuse std::{fs::read_to_string, str::FromStr};\n\nuse json_shape::JsonShape;\nuse serde_json::Value;\n\nlet json_str = read_to_string(\"./testdata/rfc-9535-example-1.json\").unwrap();\nlet json: Value = serde_json::from_str(\u0026json_str).unwrap();\nlet shape_from_value = JsonShape::from(\u0026json);\n```\n\n# Json_shape_build\n\nAuxiliary library to generate Data Structures from Json Sources:\n\n## Add dependency\n```toml\n[build-dependencies]\njson_shape_build = \"0.1\"\n```\n\nIn your `build.rs`:\n```rust,ignore\nlet dir = env!(\"CARGO_MANIFEST_DIR\");\nlet extension = \"fixture/object.json\";\nlet path = std::path::Path::new(dir).join(extension);\njson_shape_build::compile_json(\"collection_name\", \u0026[path]);\n```\n\nTo include in you project:\n```rust,ignore\nmod shapes {\n    json_shape_build::include_json_shape!(\"helloworld\");\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaomijub%2Fserde_json_shape","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaomijub%2Fserde_json_shape","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaomijub%2Fserde_json_shape/lists"}