Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON Schema Generator Python

Tags:

python

json

I am using this resource to generate the schema https://github.com/wolverdude/GenSON/

I have the below JSON File

{
 'name':'Sam',
},
{
 'name':'Jack',
}

so on ...

I am wondering how to iterate over a large JSON file. I want to parse each JSON file and pass it to GENSON to generate schema

{
  "$schema": "http://json-schema.org/schema#",
  "type": "object",
  "properties": {
     "name": {
       "type": [
        "string"
      ]
   }
},
  "required": [
    "name"
  ]
}
like image 470
sampippin Avatar asked Oct 19 '25 15:10

sampippin


1 Answers

I think you should:

import json
from genson import SchemaBuilder

builder = SchemaBuilder()
with open(filename, 'r') as f:
    datastore = json.load(f)
    builder.add_object(datastore )

builder.to_schema()

Where filename is your file path.

like image 121
Lu Chinke Avatar answered Oct 21 '25 04:10

Lu Chinke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!