Skip to content

Instantly share code, notes, and snippets.

@luisdelatorre012
Created September 13, 2024 01:35
Show Gist options
  • Save luisdelatorre012/395a2fb51cf5a7a7268b3b01f82d1414 to your computer and use it in GitHub Desktop.
Save luisdelatorre012/395a2fb51cf5a7a7268b3b01f82d1414 to your computer and use it in GitHub Desktop.
genson schema creator
import json
from pathlib import Path
from genson import SchemaBuilder
def generate_schema_from_files(directory):
builder = SchemaBuilder()
directory_path = Path(directory)
for file_path in directory_path.glob('*.json'):
with file_path.open('r') as f:
data = json.load(f)
builder.add_object(data)
return builder.to_schema()
# Example usage
directory = "path/to/your/json/files"
schema = generate_schema_from_files(directory)
print(json.dumps(schema, indent=2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment