little tool for building Wardley maps
save_graph_to_disk = function()
	local data = {next=First_available_id}
	-- save a copy of Nodes with various fields deleted
	local kvs = {}
	for k,v in pairs(Nodes) do
		v = table.copy(v)
		v.data = {}
		for i,l in ipairs(v.editor.lines) do
			table.insert(v.data, l.data)
		end
		v.editor = nil
		v.show_cursor = nil
		table.insert(kvs, {k, v})
	end
	-- sort the copy to avoid spurious diffs in version control
	table.sort(kvs, function(a, b) return a[1] < b[1] end)
	data.nodes = Nodes
	local f = App.open_for_writing(Filename)
	f:write('{ "next" : '..First_available_id..', "nodes" : {\n')
	for i,kv in ipairs(kvs) do
		if i > 1 then
			f:write(',')
		end
		f:write('"'..kv[1]..'": '..json.encode(kv[2])..'\n')
	end
	f:write('}}\n')
	f:close()
end