nalmadi / fix8

Fix8 (Fixate) is an Open-Source GUI Tool for Working with Eye Tracking Data in Reading Tasks.
Mozilla Public License 2.0
3 stars 0 forks source link

better JSON format #156

Closed nalmadi closed 3 weeks ago

nalmadi commented 3 weeks ago

The JSON format you're using is a bit odd because you are using a dictionary/object to represent ordered data (which should naturally be a list/array). And the indices are odd-only strings which is not easy to work with numerically. This is not super great from the point of view of interoperability because it's not straightforward to read in data produced by Fix8. For example, I'd have to do something like this:

imported_fix8_data = read_json(...) n_fixations = max([int(key) for key in imported_fix8_data]) fixations = [] for i in range(n_fixations): if i in imported_fix8_data: fixations.append(imported_fix8_data[i]) else: pass

nalmadi commented 3 weeks ago

Our two objectives are making the JSON file as simple as possible and allow users to add more details to their files without the possibility of breaking the code. Therefore, we updated our JSON format to reflect these two objectives by maintaining a dictionary where fixations are represented as a simple list. If users decide to add other details to their files such as participant ID or trial number (or anything else), they are able to do so without needing to change anything in how Fix8 reads their files. For example, here’s the new JSON format: new_json_data = { 'participant': '1', 'trial': '3', 'fixations': [[1, 2, 3], [4, 5, 6]] }

Or even simpler: new_json_data = { 'fixations': [[1, 2, 3], [4, 5, 6]] }

And this format in another code is as simple as this: with open(trial_3.json') as file: data = json.load(file)

print(data['fixations'])

[X] updated read JSON file with backward compatibility [X] updated save JSON to the new format [X] updated the CSV to JSON converter [X] updated the JSON to CSV converter [X]