diff --git a/contributors.md b/contributors.md index 6f720c48..af9f922e 100644 --- a/contributors.md +++ b/contributors.md @@ -3,6 +3,7 @@ The following people have contributed to the development of jsPsych by writing c * Josh de Leeuw - https://github.com/jodeleeuw * Jonas Lambers * Shane Martin - https://github.com/shamrt +* Adrian Oesch - https://github.com/adrianoesch * Marian Sauter - https://github.com/mariansauter * Tim Vergenz - https://github.com/vergenzt * Erik Weitnauer - https://github.com/eweitnauer diff --git a/docs/markdown_docs/core_library/jspsych-data.md b/docs/markdown_docs/core_library/jspsych-data.md index 05e4cda4..7ea62e9c 100644 --- a/docs/markdown_docs/core_library/jspsych-data.md +++ b/docs/markdown_docs/core_library/jspsych-data.md @@ -97,6 +97,29 @@ Generate a CSV formatted string containing all of the data generated in the expe var csvString = jsPsych.data.dataAsCSV(); ``` +--- +## jsPsych.data.dataAsJSON + +``` +jsPsych.data.dataAsJSON() +``` + +### Return value + +Returns a string in JSON format + +### Description + +Generate a JSON formatted string containing all of the data generated in the experiment. + +### Examples + +#### Basic example +```javascript +var jsonString = jsPsych.data.dataAsJSON(); +``` + + --- ## jsPsych.data.displayData diff --git a/docs/markdown_docs/core_library/overview.md b/docs/markdown_docs/core_library/overview.md index d0159325..f85cf668 100644 --- a/docs/markdown_docs/core_library/overview.md +++ b/docs/markdown_docs/core_library/overview.md @@ -24,6 +24,7 @@ Every jsPsych experiment utilizes the core library (contained in the `jspsych.js * [jsPsych.data.addDataToLastTrial](jspsych-data.md#jspsychdataadddatatolasttrial) * [jsPsych.data.addProperties](jspsych-data.md#jspsychdataaddproperties) * [jsPsych.data.dataAsCSV](jspsych-data.md#jspsychdatadataascsv) +* [jsPsych.data.dataAsJSON](jspsych-data.md#jspsychdatadataasjson) * [jsPsych.data.displayData](jspsych-data.md#jspsychdatadisplaydata) * [jsPsych.data.getData](jspsych-data.md#jspsychdatagetdata) * [jsPsych.data.getLastChunkData](jspsych-data.md#jspsychdatagetlastchunkdata) diff --git a/jspsych.js b/jspsych.js index e02ae94b..20df5c68 100755 --- a/jspsych.js +++ b/jspsych.js @@ -645,6 +645,11 @@ jsPsych.data = (function() { return JSON2CSV(dataObj); }; + module.dataAsJSON = function() { + var dataObj = module.getData(); + return JSON.stringify(dataObj); + }; + module.localSave = function(filename, format) { var data_string;