import json


def load_file_to_json(filename):
	"""
	Loads a file into a JSON object. Apart from loading the file into JSON, this function also removes
	any comments (denoted with #) and imports any other JSON objects (denoted with __LOAD__filename).
	
	:param filename: the filename of the file to be loaded.
	:returns: the JSON object that is contained in the file.
	"""
	datalines = []
	with open(filename) as infile:
		for line in infile:
			comment = line.find('#')
			if comment >= 0:
				line = line[:comment]
			datalines.append(line)
	data = json.loads(''.join(datalines))
	def recurse(tdata):
		for element in tdata:
			if type(tdata[element]) is dict:
				recurse(tdata[element])
			elif type(tdata[element]) is str and tdata[element].startswith('__LOAD__'):
				nestedfilename = "properties/" + tdata[element][8:] + ".json"
				tdata[element] = json.loads(json.dumps(load_file_to_json(nestedfilename)))
	recurse(data)
	return data