3

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"
  ]
}
sampippin
  • 123
  • 1
  • 2
  • 12

1 Answers1

10

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.

Lu Chinke
  • 622
  • 2
  • 8
  • 27
  • File size is too big (around 1GB) I was wondering if there is a memory efficient way to this? – sampippin May 08 '19 at 15:26
  • [Searched in 5 seconds](https://stackoverflow.com/questions/10382253/reading-rather-large-json-files-in-python) – Lu Chinke May 08 '19 at 15:28
  • IJSON is good for 1 Big JSON object. I have multiple json objects in one file. thanks for sharing the link though – sampippin May 08 '19 at 15:31