Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Jatos export results in JSON format

edited July 23 in JATOS

We use jsPsych to run our experiments on a JATOS server. jsPsych outputs results in JSON form, which is more robust than using CSV since there is no conversion to CSV. But when we export all the results as a single file from JATOS, the JSON file is unreadable using R's fromJSON function from jsonlite . Importing a single participants data works perfectly. Does anyone know of a way around this or would this require changing JATOS itself? Or is there something we can do on the jsPsych side? Having output in JSON becomes unusable if we have to save each file individually.


  • Hi Amunn,

    No, there's no need to save each file individually, you just need a little bit of data wrangling in R.

    There are a couple of old posts asking similar questions, I couldn't find them just now. Could you post the error message you get when trying to use fromJSON ?

    Here's an example for reading JSON data from several participants. It wasn't jsPsych, but if you say that reading a single participant works, this might already help, or at least give you a hint to where to begin.

    #load necessary libraries
    library(jsonlite) #reads in json strings
    # Take all exported text files from JATOS.
    # This can either be a single .txt file with all the study results exported at once
    # Or a list of individual results
    # They can come from either the component or the study results view, but they should contain data from the task component alonedataFiles <- list.files(path = here(), pattern = ".txt")
    allJSONs <- readChar(here(dataFiles),$size)
    singleJSONs <- Hmisc::string.break.line(allJSONs)
    nSubj <- length(singleJSONs[[1]])
    for (subj in 1:nSubj) {
      if (length(dataFiles) == 1) {
        resultData <- jsonlite::fromJSON(singleJSONs[[1]][subj])
      } else {
        resultData <-
      # Do whatever you need with your data 

    Hope this helps, otherwise feel free to send a minimal version of your data and the code you're using to read it. I'll try to have a look at it



  • edited July 24

    Thanks, Elisa. This didn't seem to do the trick for me. Here's a sample output file from a test experiment containing two runs:

    [{"response":{"test_date":"2022-07-24","experimenter_name":"Sara"},"trial_type":"survey-html-form","trial_index":0,"subject_id":"1","test_date":"2022-07-24","experimenter_name":"Sara"},{"stimulus":"<p>What about this</p>","response":0,"trial_type":"html-button-response","trial_index":1,"subject_id":"1","test_date":"2022-07-24","experimenter_name":"Sara"},{"stimulus":"<p>What about that</p>","response":1,"trial_type":"html-button-response","trial_index":2,"subject_id":"1","test_date":"2022-07-24","experimenter_name":"Sara"},{"stimulus":"The task is over","response":" ","trial_type":"html-keyboard-response","trial_index":3,"subject_id":"1","test_date":"2022-07-24","experimenter_name":"Sara"}]
    [{"response":{"test_date":"2022-07-24","experimenter_name":"Alan"},"trial_type":"survey-html-form","trial_index":0,"subject_id":"1","test_date":"2022-07-24","experimenter_name":"Alan"},{"stimulus":"<p>What about this</p>","response":0,"trial_type":"html-button-response","trial_index":1,"subject_id":"1","test_date":"2022-07-24","experimenter_name":"Alan"},{"stimulus":"<p>What about that</p>","response":0,"trial_type":"html-button-response","trial_index":2,"subject_id":"1","test_date":"2022-07-24","experimenter_name":"Alan"},{"stimulus":"The task is over","response":" ","trial_type":"html-keyboard-response","trial_index":3,"subject_id":"1","test_date":"2022-07-24","experimenter_name":"Alan"}]

    If I try to simply load this file using fromJSON('test.txt') I get the following error:

    Error in parse_con(txt, bigint_as_char) : parse error: trailing garbage
              "experimenter_name":"Sara"}] [{"response":{"test_date":"2022
                         (right here) ------^

    When I apply your R code to this, the resulting dataframe has 4 observations of 7 variables, instead of 8 observations of 7 variables.

    I've written a python script to convert the data to a format that fromJSON can read. It can be found [here]( but I'd be interested in a pure R solution too.



  • Hi Alan,

    I had a look at your GitHub page. I not too familiar with python but that seems like an overkill! Here is a solution in R that takes about 3 lines of code

    library(here) #not strictly necessary. this is for me to load the file
    data <- readtext(here("testData.txt"))
    #This is wrong and reproduces your error
    data_better <- str_replace(data$text, fixed("}]\n[{"), "},{")   
    #This is correct (as far as I can tell) and gives you the 8 observations of 7 columns/variables
    data_df <- fromJSON(data_better)

    Hope this helps but, again, do let me know if this doesn't solve your problem. You might need to include an additional replacement for those cases where you don't have a line break between the end and start of the square brackets.



  • Hi Elisa, this helps a lot!

    And I agree that the python code is overkill, but I also find that snippets of R code are harder to use over and over, and since I like reusable code, it works for me especially since I need tools that can be distributed to students in my lab. I guess I need to learn how to make an R package.

    What would be even nicer is if JATOS could output the collected runs as valid JSON itself, so that no post-processing is needed whether in R or through a script.


  • Hi amunn,

    What would be even nicer is if JATOS could output the collected runs as valid JSON itself, so that no post-processing is needed whether in R or through a script.

    The thing is that JATOS does not know about the format of your result data. They might be CSV, XML, or JSON (or any other text format). Some people already encoded binary data with base64 to text. It would be no problem for JATOS to turn the format you are using in your experiment (one JSON object per line or JSONL / NDJSON) into JSON (just add [ and ] in the beginning and end and a comma instead of line-breaks), but JATOS does not know that you have JSON. Actually, in other cases like the study log, JATOS does this already.

    All that said we might add a auto-recognition mechanism to JATOS in one of the next releases. We are discussing this currently whether that makes sense. If we decide to implement this feature JATOS will recognize the JSON format of your single result data and auto-convert the JSONL format of the current result data export file into proper JSON.



  • edited July 25

    Hi Kristian,

    I appreciate the problem, and I don't even think that autodetection is necessary. It would help even to have this as an export option chosen by the user when results are exported. I don't know if that would be an easier solution, but it would certainly be perfectly acceptable. Or alternatively some hooks within jatos.js that users could use as needed.


Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games