Write JSON Schema in Python DSL

There is a JSON Schema that defines a JSON schema in JSON. However, it is troublesome to write JSON Schema by hand, so there is a tool for creating it. Among them, I will briefly explain a package called jsl that created a JSON Schema DSL in Python.

Use the following JSON Schema as a sample.

{
	"title": "Example Schema",
	"type": "object",
	"properties": {
		"firstName": {
			"type": "string"
		},
		"lastName": {
			"type": "string"
		},
		"age": {
			"description": "Age in years",
			"type": "integer",
			"minimum": 0
		}
	},
	"required": ["firstName", "lastName"]
}

If this is defined using jsl, it will be as follows.

import jsl

class Example(jsl.Document):
    class Options(object):
        title = "Example Schema"
    firstName = jsl.StringField(required=True)
    lastName = jsl.StringField(required=True)
    age = jsl.IntField(description="Age in years", minimum=0)

If you want to output this, use the class method get_schema.

import json

print(json.dumps(Example.get_schema(ordered=True), indent=4))

reference

Recommended Posts

Write JSON Schema in Python DSL
Read and write JSON files in Python
Handling json in python
Write Python in MySQL
Easily format JSON in Python
Write Pandoc filters in Python
Write beta distribution in Python
Write python in Rstudio (reticulate)
Write a binary search in Python
Write an HTTP / 2 server in Python
Write AWS Lambda function in Python
Dynamically load json type in python
Write A * (A-star) algorithm in Python
Handling of JSON files in Python
Write selenium test code in python
Write a pie chart in Python
Write a vim plugin in Python
Write a depth-first search in Python
Python #JSON
Write C unit tests in Python
Write documentation in Sphinx with Python Livereload
Data input / output in Python (CSV, JSON)
Write the test in a python docstring
Create a JSON object mapper in Python
Write a short property definition in Python
Write O_SYNC file in C and Python
Write a Caesar cipher program in Python
Write a simple greedy algorithm in Python
Write python modules in fortran using f2py
Write a simple Vim Plugin in Python 3
How to write Ruby to_s in Python
Quadtree in Python --2
Python in optimization
CURL in python
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3