many changes to support saving the json structure to the local sql database