Child pages
  • Navigating through JSON properties

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Sometimes JSON structures are logical and easy to use, sometimes they are not (Accessing Insight object properties), and sometimes it is something in-between

For example a recent deprecation and removal of a createmeta service in Jira 9 https://confluence.atlassian.com/jiracore/jira-9-4-rest-api-change-log-1178876796.html#Jira9.4RESTAPIchangelog-9.0 and substitution it with new endpoints returning a "slightly" different structures

...

Expand
Code Block
{
  "maxResults": 50,
  "startAt": 0,
  "total": 15,
  "isLast": true,
  "values": [
    {
      "required": false,
      "schema": {
        "type": "user",
        "system": "assignee"
      },
      "name": "Assignee",
      "fieldId": "assignee",
      "autoCompleteUrl": "http://jira.vertuna.com:8080/rest/api/latest/user/assignable/search?issueKey=null&username=",
      "hasDefaultValue": false,
      "operations": [
        "set"
      ]
    },
    {
      "required": false,
      "schema": {
        "type": "array",
        "items": "attachment",
        "system": "attachment"
      },
      "name": "Attachment",
      "fieldId": "attachment",
      "hasDefaultValue": false,
      "operations": [
        
      ]
    },
    {
      "required": false,
      "schema": {
        "type": "array",
        "items": "component",
        "system": "components"
      },
      "name": "Component/s",
      "fieldId": "components",
      "hasDefaultValue": false,
      "operations": [
        "add",
        "set",
        "remove"
      ],
      "allowedValues": [
        
      ]
    },
    {
      "required": false,
      "schema": {
        "type": "any",
        "custom": "com.pyxis.greenhopper.jira:gh-epic-link",
        "customId": 10102
      },
      "name": "Epic Link",
      "fieldId": "customfield_10102",
      "hasDefaultValue": false,
      "operations": [
        "set"
      ]
    },
    {
      "required": false,
      "schema": {
        "type": "string",
        "system": "description"
      },
      "name": "Description",
      "fieldId": "description",
      "hasDefaultValue": false,
      "operations": [
        "set"
      ]
    },
    {
      "required": false,
      "schema": {
        "type": "date",
        "system": "duedate"
      },
      "name": "Due Date",
      "fieldId": "duedate",
      "hasDefaultValue": false,
      "operations": [
        "set"
      ]
    },
    {
      "required": false,
      "schema": {
        "type": "array",
        "items": "version",
        "system": "fixVersions"
      },
      "name": "Fix Version/s",
      "fieldId": "fixVersions",
      "hasDefaultValue": false,
      "operations": [
        "set",
        "add",
        "remove"
      ],
      "allowedValues": [
        
      ]
    },
    {
      "required": false,
      "schema": {
        "type": "array",
        "items": "issuelinks",
        "system": "issuelinks"
      },
      "name": "Linked Issues",
      "fieldId": "issuelinks",
      "autoCompleteUrl": "http://jira.vertuna.com:8080/rest/api/2/issue/picker?currentProjectId=&showSubTaskParent=true&showSubTasks=true&currentIssueKey=null&query=",
      "hasDefaultValue": false,
      "operations": [
        "add"
      ]
    },
    {
      "required": true,
      "schema": {
        "type": "issuetype",
        "system": "issuetype"
      },
      "name": "Issue Type",
      "fieldId": "issuetype",
      "hasDefaultValue": false,
      "operations": [
        
      ],
      "allowedValues": [
        {
          "self": "http://jira.vertuna.com:8080/rest/api/2/issuetype/10003",
          "id": "10003",
          "description": "A task that needs to be done.",
          "iconUrl": "http://jira.vertuna.com:8080/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype",
          "name": "Task",
          "subtask": false,
          "avatarId": 10318
        }
      ]
    },
    {
      "required": false,
      "schema": {
        "type": "array",
        "items": "string",
        "system": "labels"
      },
      "name": "Labels",
      "fieldId": "labels",
      "autoCompleteUrl": "http://jira.vertuna.com:8080/rest/api/1.0/labels/suggest?query=",
      "hasDefaultValue": false,
      "operations": [
        "add",
        "set",
        "remove"
      ]
    },
    {
      "required": false,
      "schema": {
        "type": "priority",
        "system": "priority"
      },
      "name": "Priority",
      "fieldId": "priority",
      "hasDefaultValue": true,
      "operations": [
        "set"
      ],
      "allowedValues": [
        {
          "self": "http://jira.vertuna.com:8080/rest/api/2/priority/1",
          "iconUrl": "http://jira.vertuna.com:8080/images/icons/priorities/highest.svg",
          "name": "Highest",
          "id": "1"
        },
        {
          "self": "http://jira.vertuna.com:8080/rest/api/2/priority/2",
          "iconUrl": "http://jira.vertuna.com:8080/images/icons/priorities/high.svg",
          "name": "High",
          "id": "2"
        },
        {
          "self": "http://jira.vertuna.com:8080/rest/api/2/priority/3",
          "iconUrl": "http://jira.vertuna.com:8080/images/icons/priorities/medium.svg",
          "name": "Medium",
          "id": "3"
        },
        {
          "self": "http://jira.vertuna.com:8080/rest/api/2/priority/4",
          "iconUrl": "http://jira.vertuna.com:8080/images/icons/priorities/low.svg",
          "name": "Low",
          "id": "4"
        },
        {
          "self": "http://jira.vertuna.com:8080/rest/api/2/priority/5",
          "iconUrl": "http://jira.vertuna.com:8080/images/icons/priorities/lowest.svg",
          "name": "Lowest",
          "id": "5"
        }
      ],
      "defaultValue": {
        "self": "http://jira.vertuna.com:8080/rest/api/2/priority/3",
        "iconUrl": "http://jira.vertuna.com:8080/images/icons/priorities/medium.svg",
        "name": "Medium",
        "id": "3"
      }
    },
    {
      "required": true,
      "schema": {
        "type": "project",
        "system": "project"
      },
      "name": "Project",
      "fieldId": "project",
      "hasDefaultValue": false,
      "operations": [
        "set"
      ],
      "allowedValues": [
        {
          "self": "http://jira.vertuna.com:8080/rest/api/2/project/10100",
          "id": "10100",
          "key": "TEST",
          "name": "TEST",
          "projectTypeKey": "software",
          "avatarUrls": {
            "48x48": "http://jira.vertuna.com:8080/secure/projectavatar?avatarId=10324",
            "24x24": "http://jira.vertuna.com:8080/secure/projectavatar?size=small&avatarId=10324",
            "16x16": "http://jira.vertuna.com:8080/secure/projectavatar?size=xsmall&avatarId=10324",
            "32x32": "http://jira.vertuna.com:8080/secure/projectavatar?size=medium&avatarId=10324"
          }
        }
      ]
    },
    {
      "required": true,
      "schema": {
        "type": "user",
        "system": "reporter"
      },
      "name": "Reporter",
      "fieldId": "reporter",
      "autoCompleteUrl": "http://jira.vertuna.com:8080/rest/api/latest/user/search?username=",
      "hasDefaultValue": false,
      "operations": [
        "set"
      ]
    },
    {
      "required": true,
      "schema": {
        "type": "string",
        "system": "summary"
      },
      "name": "Summary",
      "fieldId": "summary",
      "hasDefaultValue": false,
      "operations": [
        "set"
      ]
    },
    {
      "required": false,
      "schema": {
        "type": "timetracking",
        "system": "timetracking"
      },
      "name": "Time Tracking",
      "fieldId": "timetracking",
      "hasDefaultValue": false,
      "operations": [
        "set",
        "edit"
      ]
    }
  ]
}

It is now an array of "values", where each field is an independent object in the array


Now imagine we want to access the values of a "Priority" object and show them as dropdown options in ConfiForms web-service dropdown field

...

  • You can access the field's values by index in the array
  • You can access it by property field value match


You can see the structure looks like this (we usually use https://jsonviewer.stack.hu/ to visualize that) and the priority's field values are behind the element by index 10

Image Added

So the "Root to use" in the web-service will look like

Code Block
values[10].allowedValues

If accessing it by index does not look like "your thing" - there is another way. You can do it by property value match

Here is how

Code Block
values.(fieldId=priority).allowedValues

So, it will access the "values" array and will look for objects/elements inside it matching their field "fieldId" against the given value (priority)


Just in case if you are curious on how the complete configuration for a web-service backed dropdown field looks like (backed by Jira 9 (and cloud) new createmeta service - https://docs.atlassian.com/software/jira/docs/api/REST/9.7.1/#api/2/issue-getCreateIssueMetaProjectIssueTypes)

Image Added