import csv, io, json
data = '''X Y
1 1
2 2
3 3
4 4
5 5'''
f = io.StringIO(data)
reader = csv.DictReader(f, delimiter=' ')
json.dumps(list(reader))
# '[{"X": "1", "Y": "1"}, {"X": "2", "Y": "2"}, {"X": "3", "Y": "3"}, {"X": "4", "Y": "4"}, {"X": "5", "Y": "5"}]'