Modified script to write to the database, in a sensible JSON format