title: Parsing json into Insert statements with Python
body: <p>I have a file which contains several json records. I have to parse this file and load each of the jsons to a particular SQL-Server table. However, the table might not exist on the database, in which case I have to also create it first before loading. So, I have to parse the json file and figure out the fields/columns and create the table. Then I will have to <code>de-serialize</code> the jsons into records and insert them into the table created. However, the caveat is that some fields in the json are optional i.e. a field might be absent from one json record but could be present in another record. Below is an example file with 3 records :-</p>
  
  <pre><code>{ id : 1001, 
    name : "John", 
    age : 30 
  } , 
  
  { id : 1002,
    name : "Peter",
    age : 25
  },
  
  { id : 1002,
    name : "Kevin",
    age : 35,
    salary : 5000
  },
  </code></pre>
  
  <p>Notice that the field <em>salary</em> appears only in the 3rd record. The results should be :-</p>
  
  <pre><code>CREATE TABLE tab ( id int, name varchar(100), age int, salary int );
  
  INSERT INTO tab (id, name, age, salary) values (1001, 'John', 30, NULL)
  INSERT INTO tab (id, name, age, salary) values (1002, 'Peter', 25, NULL)
  INSERT INTO tab (id, name, age, salary) values (1003, 'Kevin', 35, 5000)
  </code></pre>
  
  <p>Can anyone please help me with some pointers as I am new to Python. Thanks.</p>