0
votes

I'm using jmeter v2.13 and jp@gc - JSON Path Extractor.

Here is my JSON sample:

{
  "views": [{
      "id": 9701,
      "name": " EBS: EAS: IDC (EAS MBT IDC)",
      "canEdit": true,
      "sprintSupportEnabled": true,
      "filter": {
        "id": 55464,
        "name": "Filter for EBS: EAS: IDC & oBill Boar",
        "query": "project = \"EBS: EAS: IDC\"",
        "owner": {},
        "canEdit": false,
        "isOrderedByRank": true,
        "permissionEntries": [{
          "values": [{
            "type": "Shared with the public",
            "name": ""
          }]
        }]
      },
      "boardAdmins": {}
    },
    {}
  ]
}

Is it possible to extract views[x].id where there exists an entry views[x].filter.permissionEntries[*].values[*].type that equals Shared with the public?

How would I do it?

Thanks

1

1 Answers

1
votes

JSON Query would look like this (I admit I didn't try it in JMeter)

$.views[?(@.filter[?(@.permissionEntries[?(@.values[?(@.type == "Shared with the public")])])])].id

Explanation:

We expect under root ($) to have views and for it to have property id. The rest (in []) are conditions to select only views items based on predefined condition. Hence $.views[conditions].id

Conditions in this case are coming one within the other, but main parts are:

  • We define condition as a filter ?(...)

  • We ask filter to look under current item (@) for a specific child item (.child), child may have its own conditions ([...]). Hence @.child[conditions]. That way we move through filter, permissionEntries, values

  • Finally we get to field values and filter it for a child type field with particular value Shared with the public. Hence @.type == "Shared with the public"

As you see it's not very intuitive, and JSON path is a bit limited. If this is a repetitive issue, and your JSON is even more complicated, you ay consider investing into a scriptable pre-processor (similar to the one explained here.