Wakefield's Daily Tips

Editing JSON code directly

If you create a survey then you edit the JSON code directly. This is not generally advisable, unless you want to copy and paste a question or page from one survey (or survey block) to another.

Here is the JSON code for a block of a survey containing three questions spread across two pages.

{
 "title": "JSON example",
 "pages": [
  {
   "name": "page1",
   "elements": [
    {
     "type": "radiogroup",
     "name": "question1",
     "choices": [
      "Item 1",
      "Item 2",
      "Item 3"
     ]
    },
    {
     "type": "matrix",
     "name": "question2",
     "columns": [
      "Column 1",
      "Column 2",
      "Column 3"
     ],
     "rows": [
      "Row 1",
      "Row 2"
     ]
    }
   ]
  },
  {
   "name": "page2",
   "elements": [
    {
     "type": "boolean",
     "name": "question3"
    }
   ]
  }
 ]
}

The survey is defined as a nested dictionary.

At the survey level we can see two keys: “title” and “pages”.

“pages” contains a list of two dictionaries, one for each page.

Each page has keys “name” and “elements”.

“elements” contains a list of dictionaries, one for each question.

Each question has keys “type” and “name” plus optional additional keys depending on the question type: “choices”, “columns” and “rows”.

If you want to move a section of your survey from one location to another, you need to identify the relevant page or question dictionary.

If a question has display logic then the question dictionary also have a “visibleif” key, such as.

     "visibleIf": "{question1} = 'Item 1'",

Pages can also have a “visibleif” key.

If you edit the JSON code and create invalid dictionaries, for example by having duplicate question names, then you will not be able to move off the JSON view until you have fixed the issue.

N.B. The block names are not shown in the question names in the JSON files but are needed in logic referring to more than one question.