Skip to content

Allow object key/value pairs to be added in the formΒ #4437

@kuhlaid

Description

@kuhlaid

Prerequisites

What theme are you using?

core

Is your feature request related to a problem? Please describe.

I manage metadata for data tables generated from research surveys. Many variables of the data tables are categorical data, so a data value of "1" may represent "Yes". The number of keys and values varies wildly but I simply use strings for both key and value for simplicity (as there are other ways to define if the key/value pairs are numeric, string, etc. using other schema elements). An example of variable/columns with categorical data might be the following (where 'category' represents the data possibilities):

{
      "name": "E03PASKR",
      "surveyQuestion": "On MOST days of ANY ONE MONTH in the LAST 12 MONTHS did you have pain, aching, or stiffness in any of the following? Please rate as none, mild, moderate, or severe. - Right - Knee",
      "label": "Right Knee - pain, aching, or stiffness on MOST days of ANY ONE MONTH in the LAST 12 MONTHS",
      "source": "Online survey",
      "value": {
         "format": "categorical",
         "dataType": "Int64",
         "unique": "False",
         "category": {
            "0": "None",
            "1": "Mild",
            "2": "Moderate",
            "3": "Severe",
            "888": "No response"
         }
      }
   }

My schema typically looks like:

"category": {
  "title": "Categorical variable",
  "description": "For categorical variables, this value lists the numeric values and their labels.",
  "type": "object",
  "patternProperties": {
    "^.*$": {
      "type": "string"
    }
  }
}

It would be useful if the jsonschema form would allow a user to create object key/value string pairs of data. This would be similar to how arrays are handled in the form I'm assuming. Validation of patternProperties would likely be a nightmare so I'm not asking for that.

I had thought of splitting out my category keys and values into separate arrays, but I cannot have the keys and values disassociating from one another as they are explicitly linked together, so the possibility of the keys or values getting out of order in the arrays is preventing that approach.

Describe the solution you'd like

Instances of the following would trigger the form to allow the user to add string key/value pairs to a data object. No validation would be triggered. This would be a good starting point for addressing the need for key/value data pairs in the form.

  "patternProperties": {
    "^.*$": {
      "type": "string"
    }
  }

The form elements would function like an array with a new item button at the least (ordering would be nice). Instead on one field per item there would be two with maybe a simple format of the following per item (where the underlines represent data fields):

____________ : ____________

Describe alternatives you've considered

Again, I considered separate key/value arrays for my categorical data but the most important thing is that the key/value pair remain paired together. So separating the pairs into individual arrays can lead to data being mislabeled.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions