{"id":18739526,"url":"https://github.com/thehoneymad/nerdcats.jsonschemadefaults","last_synced_at":"2025-08-01T04:35:57.710Z","repository":{"id":87024377,"uuid":"84720863","full_name":"thehoneymad/NerdCats.JsonSchemaDefaults","owner":"thehoneymad","description":"Generate JSON from default values in JSON Schema","archived":false,"fork":false,"pushed_at":"2017-09-13T17:09:46.000Z","size":207,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-16T06:48:21.262Z","etag":null,"topics":["dotnet-core","dotnetcore","json","json-schema","json-schemas","netstandard"],"latest_commit_sha":null,"homepage":"","language":"C#","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/thehoneymad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","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":"2017-03-12T11:37:40.000Z","updated_at":"2024-05-19T12:46:02.000Z","dependencies_parsed_at":"2023-05-30T06:00:09.881Z","dependency_job_id":null,"html_url":"https://github.com/thehoneymad/NerdCats.JsonSchemaDefaults","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thehoneymad/NerdCats.JsonSchemaDefaults","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thehoneymad%2FNerdCats.JsonSchemaDefaults","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thehoneymad%2FNerdCats.JsonSchemaDefaults/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thehoneymad%2FNerdCats.JsonSchemaDefaults/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thehoneymad%2FNerdCats.JsonSchemaDefaults/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thehoneymad","download_url":"https://codeload.github.com/thehoneymad/NerdCats.JsonSchemaDefaults/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thehoneymad%2FNerdCats.JsonSchemaDefaults/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268171106,"owners_count":24207410,"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":["dotnet-core","dotnetcore","json","json-schema","json-schemas","netstandard"],"created_at":"2024-11-07T15:36:08.697Z","updated_at":"2025-08-01T04:35:57.654Z","avatar_url":"https://github.com/thehoneymad.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Json Schema Defaults for .net\nA simple helper library to generate default JSON from a JSONSchema. Written in .NET standard for maximum portability and proudly [JSON.net](https://github.com/JamesNK/Newtonsoft.Json) and [Newtonsoft.Json.Schema](https://github.com/JamesNK/Newtonsoft.Json.Schema) driven.\n\n## Install\nYou can install it from [Nuget](https://www.nuget.org/packages/NerdCats.JsonSchemaDefaults/) using\n\n```\nPM\u003e Install-Package NerdCats.JsonSchemaDefaults\n```\n\n## How to Build\nClone the repo, run `dotnet restore` and `dotnet build`. Built on Visual Studio 2017 with .net core SDK 1.1.0\n\n## Usage\n\n#### Generate default JSON example 1\nSample JSON schema:\n\n```json\n{\n    \"title\": \"Album Options\",\n    \"type\": \"object\",\n    \"properties\": {\n        \"sort\": {\n                \"type\" : \"string\",\n                \"default\": \"id\"\n            },\n        \"per_page\" : {\n                \"default\" : 30,\n                \"type\": \"integer\"\n        }\n    }\n}\n```\n\nTo generate a JSON with all default values defined here use `SchemaDefaultGenerator` like the following:\n\n```csharp\nvar schemaDefaultGenerator = new SchemaDefaultGenerator();\nvar defaultJSON = schemaDefaultGenerator.GetDefaults(JObject.Parse(\"{\" +\n                \"\\\"title\\\": \\\"Album Options\\\", \" +\n                \"\\\"type\\\": \\\"object\\\",\" +\n                \"\\\"properties\\\": {\" +\n                \"   \\\"sort\\\": {\" +\n                \"       \\\"type\\\": \\\"string\\\",\" +\n                \"       \\\"default\\\": \\\"id\\\"\" +\n                \"   },\" +\n                \"   \\\"per_page\\\": {\" +\n                \"       \\\"default\\\": 30,\" +\n                \"       \\\"type\\\": \\\"integer\\\"\" +\n                \"   }\" +\n                \"}}\"));\n\nvar expectedResult = JObject.Parse(\"{ sort: 'id', per_page: 30 }\");\nAssert.IsTrue(JToken.DeepEquals(defaultJSON, expectedResult));\n```\n\nGenerated default JSON would be :\n\n```json\n    {\n        \"sort\": \"id\",\n        \"per_page\": 30\n    }\n```\n\nYou can also opt for the sweet extension method for `JSchema` class like the following:\n\n```csharp\nvar schema = JSchema.Parse(\"{\" +\n                \"\\\"title\\\": \\\"Album Options\\\", \" +\n                \"\\\"type\\\": \\\"object\\\",\" +\n                \"\\\"properties\\\": {\" +\n                \"   \\\"sort\\\": {\" +\n                \"       \\\"type\\\": \\\"string\\\",\" +\n                \"       \\\"default\\\": \\\"id\\\"\" +\n                \"   },\" +\n                \"   \\\"per_page\\\": {\" +\n                \"       \\\"default\\\": 30,\" +\n                \"       \\\"type\\\": \\\"integer\\\"\" +\n                \"   }\" +\n                \"}}\");\nvar defaultJSON = schema.GetDefaultJSON();\nvar expectedResult = JObject.Parse(\"{ sort: 'id', per_page: 30 }\");\n\nAssert.IsTrue(JToken.DeepEquals(defaultJSON, expectedResult));\n```\n\n#### Generate default JSON example 2\n\nLet's up the ante a bit with local references and allOf operator\n\nSample JSON schema:\n\n```json\n{\n    \"type\": \"object\",\n    \"properties\": {\n        \"farewell_to_arms\": {\n            \"allOf\": [\n                {\n                    \"$ref\": \"#/definitions/book\"\n                },\n                {\n                    \"properties\": {\n                            \"price\": {\n                                \"default\" : 30,\n                            }\n                        }\n                }\n            ]\n        },\n        \"for_whom_the_bell_tolls\": {\n            \"allOf\": [\n                {\n                    \"$ref\": \"#/definitions/book\"\n                },\n                {\n                    \"properties\": {\n                        \"price\": {\n                            \"default\": 100\n                        }\n                    }\n                }\n            ]\n        }\n    },\n    \"definitions\": {\n        \"book\": {\n            \"type\": \"object\" ,\n            \"properties\": {\n                \"author\": {\n                    \"type\": \"string\",\n                    \"default\": \"Hemingway\",\n                },\n                \"price\": {\n                    \"type\": \"integer\",\n                    \"default\": 10,\n                }\n            }\n        }\n    }\n}\n```\n\nTo generate a default JSON from this let's go the same way we have gone a moment ago\n\n```csharp\nvar schemaDefaultGenerator = new SchemaDefaultGenerator();\nvar schemaJson = \"{\" +\n                \"type: 'object',\" +\n                \"properties: {\" +\n                    \"farewell_to_arms: { \" +\n                        \"allOf: [\" +\n                            \"{'$ref': '#/definitions/book'},\" +\n                            \"{'properties': {\" +\n                                    \"price: {\" +\n                                        \"default : 30\" +\n                                    \"}\" +\n                            \"}\" +\n                        \"}]\" +\n                     \"},\" +\n                    \"for_whom_the_bell_tolls: {\" +\n                        \"allOf: [\" +\n                            \"{'$ref': '#/definitions/book'}, \" +\n                            \"{ properties: { \" +\n                                \" price: { \" +\n                                    \"default: 100 \" +\n                                    \"}\" +\n                                \"}\" +\n                             \"}\" +\n                           \"]\" +\n                        \"}\" +\n                  \"},\" +\n                \"definitions: {\" +\n                    \"book: {\" +\n                        \"type: 'object',\" +\n                        \"properties: {\" +\n                            \"author: {\" +\n                                \"type: 'string',\" +\n                                \"default: 'Hemingway'\" +\n                             \"},\" +\n                            \"price: {\" +\n                                \"type: 'integer',\" +\n                                \"default: 10\" +\n                            \"}\" +\n                        \"}\" +\n                    \"}\" +\n                \"}\" +\n            \"}\";\n\nvar defaultJson = schemaDefaultGenerator.GetDefaults(schemaJson);\nvar expectedDefault = JObject.Parse(\"{ farewell_to_arms: { author: 'Hemingway', price: 30 }, for_whom_the_bell_tolls: { author: 'Hemingway', price: 100 } }\");\n\nAssert.IsTrue(JToken.DeepEquals(defaultJson, expectedDefault));\n```\nThe resultant default JSON would look like\n\n```json\n{\n    \"farewell_to_arms\": {\n        \"author\": \"Hemingway\",\n        \"price\": 30\n    },\n    \"for_whom_the_bell_tolls\": {\n        \"author\": \"Hemingway\",\n        \"price\": 100\n    }\n}\n```\n\n## Known Limitations\nThis library conforms to JsonSchema draft 4. This still doesn't support default values for `anyOf` and `oneOf` operator defaults.\n\n## Contributors\n\n* Swagata 'thehoneymad' Prateek @SwagataPrateek\n\n# Special mentions\nThanks goes to Eugene Tsypkin for [json-schema-defaults](https://github.com/chute/json-schema-defaults) for inspiration.\n\n\n## License\nReleased under the terms of the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthehoneymad%2Fnerdcats.jsonschemadefaults","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthehoneymad%2Fnerdcats.jsonschemadefaults","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthehoneymad%2Fnerdcats.jsonschemadefaults/lists"}