Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not so minor adjustments to JSON #1

Open
wants to merge 7 commits into
base: json-standard
Choose a base branch
from
Open

Not so minor adjustments to JSON #1

wants to merge 7 commits into from

Conversation

alexdmccabe
Copy link

I don't know how to update the .obgjen file reliably - I made the changes by writing a script that recurses over the data and changes the keys. Simple find/replace changes some of the values, too.

Any ideas?

@alexdmccabe
Copy link
Author

Also updated the question types to use underscores, and changed the booleans to proper booleans instead of strings.

@hestenet
Copy link
Owner

hestenet commented Mar 8, 2019

Oh right, I guess I did use objen now that you mention it - that's an online JSON formatter here: http://www.objgen.com/json (and I just saved the input format to a file for reference)

@alexdmccabe
Copy link
Author

Updated the objgen file to print out the same JSON I created.

@alexdmccabe
Copy link
Author

alexdmccabe commented Mar 9, 2019

I think the choices could also be simplified to a simple key -> value, for example, with age:

category_age
  id = age
  description = The age bracket of the respondent.
  questions
    how_old
      type = select_one
      self_identify b = false
      prefer_not_to_answer b = true
      does_not_apply b = true
      prompt = How old are you?
      choices
        full_set
          0-15 = 0 - 15
          15-19 = 15 - 19
          20-24 = 20 - 24
          25-29 = 25 - 29
          30-39 = 30 - 39
          40-49 = 40 - 49
          50-49 = 50 - 59
          60-69 = 60 - 69
          70-79 = 70 - 79
          80+ = 80+
          prefer-not-to-answer = Prefer not to answer
        short_set
          0-19 = 0 - 19
          20-39 = 20 - 39
          40-60 = 40 - 60
          61+ = 61+
          prefer-not-to-answer = Prefer not to answer

which produces

{
  "category_age": {
    "id": "age",
    "description": "The age bracket of the respondent.",
    "questions": {
      "how_old": {
        "type": "select_one",
        "self_identify": false,
        "prefer_not_to_answer": true,
        "does_not_apply": true,
        "prompt": "How old are you?",
        "choices": {
          "full_set": {
            "0-15": "0 - 15",
            "15-19": "15 - 19",
            "20-24": "20 - 24",
            "25-29": "25 - 29",
            "30-39": "30 - 39",
            "40-49": "40 - 49",
            "50-49": "50 - 59",
            "60-69": "60 - 69",
            "70-79": "70 - 79",
            "80+": "80+",
            "prefer-not-to-answer": "Prefer not to answer"
          },
          "short_set": {
            "0-19": "0 - 19",
            "20-39": "20 - 39",
            "40-60": "40 - 60",
            "61+": "61+",
            "prefer-not-to-answer": "Prefer not to answer"
          }
        }
      }
    }
  },

instead of this style:

category_age
  id = age
  description = The age bracket of the respondent.
  questions
    how_old
      type = select_one
      self_identify b = false
      prefer_not_to_answer b = true
      does_not_apply b = true
      prompt = How old are you?
      choices 
        full_set [0]
          id = 0-15
          value = 0-15
          label = 0 - 15
        full_set [1]
          id = 15-19
          value = 15-19
          label = 15 - 19
        full_set [2]
           id = 20-24
           value = 20-24
           label = 20 - 24
        full_set [3]
           id = 25-29
           value = 25-29
           label = 25 - 29
        full_set [4]
           id = 30-39
           value = 30-39
           label = 30 - 39
        full_set [5]
           id = 40-49
           value = 40-49
           label = 40 - 49
        full_set [6]
           id = 50-59
           value = 50-59
           label = 50 - 59
        full_set [7]
           id = 60-69
           value = 60-69
           label = 60 - 69
        full_set [8]
           id = 70-79
           value = 70-79
           label = 70 - 79
        full_set [9]
           id = 80+
           value = 80+
           label = 80+
        full_set [10]
           id = prefer-not-to-answer
           value = prefer-not-to-answer
           label = Prefer not to answer
        short_set [0]
          id = 0-19
          value = 0-19
          label = 0 - 19
        short_set [1]
          id = 20-39
          value = 20-39
          label = 20 - 39
        short_set [2]
          id = 40-60
          value = 40-60
          label = 40 - 60
        short_set [3]
          id = 61+
          value = 61+
          label = 61+
        short_set [4]
           id = prefer-not-to-answer
           value = prefer-not-to-answer
           label = Prefer not to answer

which produces

{
  "category_age": {
    "id": "age",
    "description": "The age bracket of the respondent.",
    "questions": {
      "how_old": {
        "type": "select_one",
        "self_identify": false,
        "prefer_not_to_answer": true,
        "does_not_apply": true,
        "prompt": "How old are you?",
        "choices": {
          "full_set": [
            {
              "id": "0-15",
              "value": "0-15",
              "label": "0 - 15"
            },
            {
              "id": "15-19",
              "value": "15-19",
              "label": "15 - 19"
            },
            {
              "id": "20-24",
              "value": "20-24",
              "label": "20 - 24"
            },
            {
              "id": "25-29",
              "value": "25-29",
              "label": "25 - 29"
            },
            {
              "id": "30-39",
              "value": "30-39",
              "label": "30 - 39"
            },
            {
              "id": "40-49",
              "value": "40-49",
              "label": "40 - 49"
            },
            {
              "id": "50-59",
              "value": "50-59",
              "label": "50 - 59"
            },
            {
              "id": "60-69",
              "value": "60-69",
              "label": "60 - 69"
            },
            {
              "id": "70-79",
              "value": "70-79",
              "label": "70 - 79"
            },
            {
              "id": "80+",
              "value": "80+",
              "label": "80+"
            },
            {
              "id": "prefer-not-to-answer",
              "value": "prefer-not-to-answer",
              "label": "Prefer not to answer"
            }
          ],
          "short_set": [
            {
              "id": "0-19",
              "value": "0-19",
              "label": "0 - 19"
            },
            {
              "id": "20-39",
              "value": "20-39",
              "label": "20 - 39"
            },
            {
              "id": "40-60",
              "value": "40-60",
              "label": "40 - 60"
            },
            {
              "id": "61+",
              "value": "61+",
              "label": "61+"
            },
            {
              "id": "prefer-not-to-answer",
              "value": "prefer-not-to-answer",
              "label": "Prefer not to answer"
            }
          ]
        }
      }
    }
  },

@alexdmccabe
Copy link
Author

I also removed the "self-identify" choices from the choice lists because that should be coming from the self_identify property of the question, not a choice.

@alexdmccabe
Copy link
Author

Initial implementation with these changes in D7: https://cgit.drupalcode.org/open_demographics/tree/

Needs a lot of work still, but it's a strong start, I think.

@alexdmccabe alexdmccabe changed the title Minor adjustments to JSON Not so minor adjustments to JSON Mar 9, 2019
@alexdmccabe
Copy link
Author

alexdmccabe commented Mar 9, 2019

I also removed the "self-identify" choices from the choice lists because that should be coming from the self_identify property of the question, not a choice.

We should probably do the same thing with the prefer_not_to_answer property (or do it in reverse and get rid of the property in favor of the question choice). And on that note, what is the does_not_apply property supposed to mean?

@hestenet
Copy link
Owner

I think does_not_apply may not make sense here - we'll already be able to control whether fields are required are not on the implementation level - so it seems like that should be removed.

Agree with inverting the the prefer_not_to_answer logic in the same way you changed the self-identify property.

@bookworm2000
Copy link

Looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants