Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weaming/json-schema-generator
Generate the initial json schema from your given example json.
https://github.com/weaming/json-schema-generator
json json-schema tool
Last synced: 1 day ago
JSON representation
Generate the initial json schema from your given example json.
- Host: GitHub
- URL: https://github.com/weaming/json-schema-generator
- Owner: weaming
- Created: 2018-06-25T14:31:36.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-28T11:16:43.000Z (over 5 years ago)
- Last Synced: 2024-10-13T01:36:17.105Z (about 1 month ago)
- Topics: json, json-schema, tool
- Language: Python
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JSON schema generator
Generate the initial json schema from your given example json.
## Install
pip install json-schema-generator2
## Usage
```
$ generate-json-schema help
Usage:
cat sample.json | generate-json-schema
generate-json-schema sample.json
generate-json-schema sample.json > output.schema.json
```## Envrioment variables
* `JSON_SCHEMA_ID`
* `JSON_SCHEMA_TITLE`## Special rules to determine the type
* suffix definitions
* `?`: optional
* `!`: `enum`
* `!?`: optional `enum`
* default: based on sample value
* Will update `~/.config/json-schema-generator/extra.json` to every generated object.## Example
```json
{
"account": {
"name": "",
"telephone?": "",
"nationality!?": "CHN",
"address?": "",
"city": "",
"state": "",
"zip code": "",
"balance": 100,
"child": [{
"name": "",
"age": 18,
"gender!": "BOY"
}],
"hobby": [],
"favorite numbers": [3.14]
}
}```
And the content of `extra.json`:
```
{
"title": "example title",
"description": "example description"
}
```Will produce:
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"account": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"telephone": {
"type": "string"
},
"nationality": {
"type": "string",
"enum": [
"CHN"
]
},
"address": {
"type": "string"
},
"city": {
"type": "string"
},
"state": {
"type": "string"
},
"zip code": {
"type": "string"
},
"balance": {
"type": "integer"
},
"child": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
},
"gender": {
"type": "string",
"enum": [
"BOY"
]
}
},
"required": [
"name",
"age",
"gender"
],
"additionalProperties": false,
"title": "example title",
"description": "example description"
}
},
"hobby": {
"type": "array"
},
"favorite numbers": {
"type": "array",
"items": {
"type": "number"
}
}
},
"required": [
"name",
"city",
"state",
"zip code",
"balance",
"child",
"hobby",
"favorite numbers"
],
"additionalProperties": false,
"title": "example title",
"description": "example description"
}
},
"required": [
"account"
],
"additionalProperties": false,
"title": "example title",
"description": "example description"
}
```