Updated handling of JSONobject to not cause errors if database is empty.