Material Survey Format

November 4, 2019 ยท View on GitHub

This document fully specifies the Material Survey Format, the JSON input format that defines the form and control flow.

The MaterialSurvey format is based off the SurveyJS format.

The material-survey-format.js.flow file contains the type definitions.

Quick Examples

This is a simple survey that displays a text question:

{
  questions: [
    { title: "What is your first name?", name: "firstname", type: "text" }
  ]
}

Here's a survey with a radiogroup-style question and a checkbox question:

{
  questions: [
    {
      title: "Do you like Material Survey?",
      name: "likeMaterialSurvey",
      type: "radiogroup",
      choices: ["yes", "no", "idk"]
    },
    {
      title: "Select anything you're allergic to",
      name: "allergies",
      type: "checkbox",
      choices: ["nuts", "dairy", "gluten"]
    }
  ]
}

Going further, we can create complex multi-page surveys with conditional display logic and validation!

Structure

A Material Survey can take two forms. A single page survey simply appears as follows...

{
  "questions": [/* Array<SurveyQuestion> */]
}

A multi-page survey appears as follows...

{
  pages: [/* Array<SurveyPage> /*]
}

Each survey can also have the following keys on the root object to specify different properties of the survey.

KeyDescriptionDefault
expressionLanguageThe language of conditional expressions e.g. the value of a visibleIf. See expression languages for more details on the available languages."surveyjs"

Pages

Each page uses the following format.

{
  elements: Array<Question>
}

Questions Definition

The following question types are available...

Question TypeDescription
textFreeform text (tip: use validators to force a structure)
multiline-textText with multiple lines.
radiogroupSingle choice question.
checkboxMultichoice question.
dropdownSingle choice question with many options.
multiple-dropdownMulti choice question with many options.
imagepickerSelect from a set of images.
choicerankerRank options by iteratively asking users to pick their favorite answer.
matrixdynamicA question with any number of subquestions.
booleanA yes/no question.
ratingA rating.
fileUpload a file.
sliderA numeric slider.
autocompleteAutocomplete using an API.
us-regionSelect a US Region (East Coast, Midwest, West Coast, ...)
multiple-us-regionSelect multiple US regions.
us-stateSelect a us state.
multiple-us-stateSelect multiple us states.

Each question has a base set of properties...

KeyDescription
nameRequired The answer key in the output map.
titleThe text displayed as the question title.
isRequiredShould this question be required before continuing.
hasOtherShould an "Other" field be displayed allowing free form input.
descriptionA subtext to be displayed to clarify details about this quesiton.
visibleIfExpression indicating whether or not the question should be shown.
defaultAnswerDefault answer for this question.
validatorsArray of validators to check answer.

If a question pulls from a set of possible answers (e.g. a dropdown or radiogroup) the format of a choice is either a string or an object { "value": string, "text": string } where text is how the choice is displayed and value is how it is encoded in the answer map.

text

KeyDescription
N/AN/A

multiline-text

KeyDescription
N/AN/A

radiogroup

KeyDescription
choicesArray of choices

checkbox

KeyDescription
choicesArray of choices
KeyDescription
choicesArray of choices

multiple-dropdown

KeyDescription
choicesArray of choices

imagepicker

KeyDescription
choicesArray of choices

choiceranker

KeyDescription
choicesArray of choices
choicesAtOnceNumber of choices to display at once
trialsNumber of selections to display to user

matrixdynamic

type DynamicMatrixQuestion = {
  ...BaseQuestion,
  type: "matrixdynamic",
  choices: Array<QuestionChoice>,
  columns: Array<{
    name: string,
    title?: string,
    cellType: "dropdown" | "checkbox" | "text",
    choices: Array<QuestionChoice>,
    hasOther?: boolean
  }>
}

boolean

KeyDescription
N/AN/A

rating

KeyDescription
rankings?Number of rankings
rateValues?Values of each rating
minRateDescription?Description of lowest ranking
midRateDescription?Description of middle ranking
maxRateDescription?Description of highest ranking

file

KeyDescription
maxSize?Maximum file size in bytes

slider

KeyDescription
minMinimum value
maxMaximum value
stepStep size

autocomplete

KeyDescription
requestUrlUrl to request for autocomplete response

us-region

KeyDescription
N/AN/A

multiple-us-region

KeyDescription
N/AN/A

us-state

KeyDescription
N/AN/A

multiple-us-state

KeyDescription
N/AN/A

Validators

Validators check the content of an answer and display relevant errors if a condition is not met.

The text key of each validator specifies the error text to be shown.

email

Answer should be an email.

{
  type: "email",
  text: string
}

expression

Expression should evaluate to true.

Expressions can use multiple questions.

{
  type: "expression",
  expression: string,
  text: string
}

numeric

{
  type: "numeric",
  minValue?: number,
  maxValue?: number,
  text: string
}

text

{
  type: "text",
  minLength?: number,
  maxLength?: number,
  allowDigits?: boolean,
  text: string
}

regex

{
  type: "regex",
  regex: string,
  text: string
}

answercount

{
  type: "answercount",
  text: string,
  minCount?: number,
  maxCount?: number
}

Expression Languages

LanguageDescription
surveyjsThe expression language defined by the original surveyjs project.

"surveyjs"

The expression language defined by the original surveyjs project. Details regarding this expression format can be found in the surveyjs-expression-eval.

Output Format

The output of the survey is a JSON object with a key representing each question.

e.g.

{
  "favorite-foods": ["spaghetti", "ramen"],
  "inception-rating": 4.8
}```