import lineTools import json import os # for getting script path, etc. def relativePath(path): # the only argument, path, is relative to the directory this script is stored in return os.path.join(os.path.dirname(__file__), path) lines = [lineTools.randomLine(i + 10) for i in range(10)] with open(relativePath("lines_bhw.json"), "w+") as aFile: features = [] for line in lines: features.append({ "type": "Feature", "geometry": { "type": "LineString", "coordinates": line } }) data = { "type": "FeatureCollection", "features": features } aFile.write(json.dumps(data))