Created
September 13, 2024 01:35
-
-
Save luisdelatorre012/395a2fb51cf5a7a7268b3b01f82d1414 to your computer and use it in GitHub Desktop.
genson schema creator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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