This is a major refactoring commit, which also adds functionality to write JSON inline and upload it to norch