Problem outputting nested stringified data to JSON.
See original GitHub issueIn the current implementation of jsPsych, there is a problem handling trials with complex nested data. This is most easily illustrated in the jspsych-instructions
plugin via the view_history
property in trial_data
.
The current solution implemented is to stringify the view_history
array using { view_history: JSON.stringify(view_history)... }
, which allows for sensible conversion to CSV. Without stringifying view_history
, those view_history
data would show up in the CSV as [object Object]
. However, if you attempt to get the JSON data for the experiment, it cannot later be parsed with JSON.parse
(or the json library in Python) due to problems resulting from attempting to parse a stringified JSON object within a stringified JSON object.
My current solution is to use the parse
function from the json2csv
library (available on npm) to replace the JSON2CSV
helper function in jspsych.js
. This allows me to have both sensible CSV and JSON representations of the data.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
@becky-gilbert I went ahead and worked on this in the
feature-objects-arrays-in-data
branch.It changes a core design idea: now we store objects and arrays in the data directly, instead of JSON versions of them. I updated all of the plugins that this affects, wrote a simple test to check the output of both
.json()
and.csv()
methods injsPsych.data
, and updated the CSV conversion function.Things that should probably happen before a merge:
examples
folder to see if any of the examples useJSON.parse()
on data objects that are now not JSON.Sorry for not seeing this sooner; Github does not do a good job of notifying me about activity on posts it would seem! That’s precisely the approach that I took in my own fork of the project; I’m using the json2csv library to handle the csv-ification of the jsPsych data.