Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

Summary - SINCE 4.1.27

When using some Custom Fields they may return a JSON Object as the value which made it difficult to extract the relevant value. Within JEMH 4.1.27 we have added a new method to jemhUtils which allows to manipulate JSON values more easily. This page will highlight how to extract specific information from the JSON Object.

Converting a Custom Field value into a JSON value

When we gather the value from the Custom Field it will be returned as a String value which means that it is currently not possible to manipulate the JSON data. To be able to access the JSON data you will need to use the following command to convert the Text value into a JSON value.

$jemhUtils.createJSONFromSource(String jsonSource)

Using this with a Custom Field value

$jemhUtils.createJSONFromSource($issue.getCustomFieldValue("customfield_10233"))

Extracting a Specific Object value

To extract a specific Object you will simply need to add the object name to the above and this will return the value/s for that object.e.g.

$jemhUtils.createJSONFromSource($issue.getCustomFieldValue("customfield_10233")).object

To then get the value of the next object, you will need to add the next object name. e.g. below will return Array Item1

$jemhUtils.createJSONFromSource($issue.getCustomFieldValue("customfield_10233")).object.array.name

JSON Object example:

{"object": {
        "name": "test",
        "array": {
            "name": "Array Item1",
            "id": "10003",
          },
    }
}

Extracting a specific value from a JSON Array

Sometimes the JSON object may contain an array for a specific object. To access the array value you must specify the Array to get the value by using .get() and then specifying the Array number e.g. below will return the name that is found within first array in the list (e.g.Array Item1)

$jemhUtils.createJSONFromSource($issue.getCustomFieldValue("customfield_10233")).object.array.get(0).name

JSON array example:

{"object": {
        "name": "test",
        "array": [
          {
            "name": "Array Item1",
            "id": "10003",
          },
         {
            "name":"Array Item2",
            "id": "10004",
          }
        ]
    }
}
  • No labels