Related
I need help with jq syntax on how to return the Gitlab job ID if it contains an artifact. The JSON output looks like this (removed a lot of unrelated info from it and added [...]):
[{
"id": 3219589880,
"status": "success",
"stage": "test",
"name": "job_with_no_artifact",
"ref": "main",
"tag": false,
"coverage": null,
"allow_failure": false,
"created_at": "2022-10-24T18:21:25.119Z",
"started_at": "2022-10-24T18:21:25.986Z",
"finished_at": "2022-10-24T18:21:38.464Z",
"duration": 12.478682,
"queued_duration": 0.499786,
"user": {
"id": 123456789,
[...]
},
"commit": {
"id": "5e0e1f287d20daf2036a3ca71c656dce55999265",
[...]
"pipeline": {
"id": 123456789,
[...]
"project": {
"ci_job_token_scope_enabled": false
},
"artifacts": [],
"runner": {
"id": 12270859,
[...]
},
"artifacts_expire_at": null,
"tag_list": []
}, {
"id": 3219589878,
"status": "success",
"stage": "test",
"name": "create_artifact_job_2",
"ref": "main",
"tag": false,
"coverage": null,
"allow_failure": false,
"created_at": "2022-10-24T18:21:25.111Z",
"started_at": "2022-10-24T18:21:25.922Z",
"finished_at": "2022-10-24T18:21:39.090Z",
"duration": 13.168405,
"queued_duration": 0.464364,
"user": {
"id": 123456789,
[...]
},
"commit": {
"id": "5e0e1f287d20daf2036a3ca71c656dce55999265",
[...]
},
"pipeline": {
"id": 675641982,
[...],
"project": {
"ci_job_token_scope_enabled": false
},
"artifacts_file": {
"filename": "artifacts.zip",
"size": 223
},
"artifacts": [{
"file_type": "archive",
"size": 223,
"filename": "artifacts.zip",
"file_format": "zip"
}, {
"file_type": "metadata",
"size": 153,
"filename": "metadata.gz",
"file_format": "gzip"
}],
"runner": {
"id": 12270845,
[...]
},
"artifacts_expire_at": "2022-10-25T18:21:35.859Z",
"tag_list": []
}, {
"id": 3219589876,
"status": "success",
"stage": "test",
"name": "create_artifact_job_1",
"ref": "main",
"tag": false,
"coverage": null,
"allow_failure": false,
"created_at": "2022-10-24T18:21:25.103Z",
"started_at": "2022-10-24T18:21:25.503Z",
"finished_at": "2022-10-24T18:21:41.407Z",
"duration": 15.904028,
"queued_duration": 0.098837,
"user": {
"id": 123456789,
[...]
},
"commit": {
"id": "5e0e1f287d20daf2036a3ca71c656dce55999265",
[...]
},
"pipeline": {
"id": 123456789,
[...]
},
"web_url": "WEB_URL",
"project": {
"ci_job_token_scope_enabled": false
},
"artifacts_file": {
"filename": "artifacts.zip",
"size": 217
},
"artifacts": [{
"file_type": "archive",
"size": 217,
"filename": "artifacts.zip",
"file_format": "zip"
}, {
"file_type": "metadata",
"size": 152,
"filename": "metadata.gz",
"file_format": "gzip"
}],
"runner": {
"id": 12270857,
},
"artifacts_expire_at": "2022-10-25T18:21:37.808Z",
"tag_list": []
}]
I've been trying to do either of the following using jQ:
Either:
Check if artifacts_file key exists in each iteration and if it does return the (job) id (so .[].id)
Check if artifacts array is empty in each iteration and if it is empty return the (job) id.
In both cases I'm able to do the first part but I am not sure how to return the .id key.
Related stackoverflow questions that I've been trying to utilize and adapt to my case:
jq - return array value if its length is not null
How to check for presence of 'key' in jq before iterating over the values
What I have so far: jq '[.[].artifacts[]|select(length > 0)] | .[]' which returns all the artifacts found (but it doesn't contain the .id of the job).
Checking the existence of a field using has:
.[] | select(has("artifacts_file")).id
3219589878
3219589876
Demo
Checking if a field is an empty array by comparing it to []:
.[] | select(.artifacts == []).id
3219589880
Demo
so I am working with Clickup API, there we have a number of lists we would like to fetch the data from and insert that data as a wordpress post for our website.
I have tested all the API requests with Postman and the data i get back is similar to this, basically would need to fetch the data with "custom fields", but I am not sure how to work it out with PHP, any help would be appreciated.
"custom_fields": [
{
"id": "39ed2191-443e-4d45-84d4-de9eff89cc97",
"name": "Cost",
"type": "currency",
"type_config": {
"default": null,
"precision": 2,
"currency_type": "USD"
},
"date_created": "1616008796860",
"hide_from_guests": false,
"required": false
},
{
"id": "bcca51b8-a903-4194-8d24-8e663de0618e",
"name": "Deadline",
"type": "short_text",
"type_config": {},
"date_created": "1613070997077",
"hide_from_guests": false,
"required": false
},
{
"id": "35af20c5-5469-40b6-afc7-d7e9d5f3c451",
"name": "Industry",
"type": "drop_down",
"type_config": {
"default": 0,
"placeholder": null,
"new_drop_down": true,
"options": [
{
"id": "227658be-5cc6-4c33-a539-029c13a18416",
"name": "Agriculture",
"color": null,
"orderindex": 0
},
{
"id": "2d5041ff-e557-42ae-859a-51698d01d2f7",
"name": "Automation",
"color": null,
"orderindex": 1
},
{
"id": "d2c33aa5-de68-4f16-ad79-5308893c66a6",
"name": "Beauty",
"color": null,
"orderindex": 2
},
{
"id": "bcbf40c4-bcb8-41c4-81ed-7afffca9eccd",
"name": "Construction",
"color": null,
"orderindex": 3
},
{
"id": "47bc5b7d-0fb9-4c64-8887-249e55d31f85",
"name": "Sanitation",
"color": null,
"orderindex": 4
},
{
"id": "10b0e274-4996-4cc9-9c1e-4d44f78694d1",
"name": "Travel",
"color": null,
"orderindex": 5
}
]
},
"date_created": "1639080879165",
"hide_from_guests": false,
"required": false
},
Here's a very abstract description of the possible steps you'll need to take:
Fetch the data using wp_remote_request()
Parse the data using json_decode()
Get all the data you need from the object(-s)
Create a post using wp_insert_post()
Save all the additional data in the post(-s) meta fields using update_post_meta()
I am working on jmeter and trying to get values from a Json response.
I have below Json:
`{
"linked": {},
"learning_items": [
{
"id": "3452",
"enrollable_id": "3452",
"enrollable_type": "Enrollment",
"learnable_id": "6",
"learnable_type": "CourseTemplate",
"title": "all kinda ",
"description": "",
"state": "created",
"completed_at": null,
"created_at": "2017-04-10T16:26:36.850-06:00",
"archived_at": null,
"permanently_failed": false,
"data": {
"end_at": "2017-04-16T23:59:59.000-06:00",
"expires_at": null,
"renew_by": null,
"required": true,
"score": 0,
"time_remaining": 5,
"current_position": 0,
"furthest_progress": 0,
"quiz_positions": [
2,
3,
4,
5
],
"direct_enrollment": true,
"max_quiz_attempts": null,
"attempts_count": 0,
"inactive": null,
"program": null,
"programs": [],
"in_completed_program": false,
"external_id": null,
"estimated_time": 5,
"passing_threshold": 80,
"has_certificate": false,
"course_type": "bridge",
"slide_count": 5,
"attachments_count": 1,
"attachments_count_author": 2,
"third_party_course_id": null,
"open_book": true,
"continuing_education_credits": null,
"features": [
"has_quizzes"
]
},
"tags": []
},
{
"id": "3451",
"enrollable_id": "3451",
"enrollable_type": "Enrollment",
"learnable_id": "7",
"learnable_type": "CourseTemplate",
"title": "All types",
"description": "",
"state": "active",
"completed_at": null,
"created_at": "2017-04-10T16:26:36.605-06:00",
"archived_at": null,
"permanently_failed": false,
"data": {
"end_at": "2017-04-17T23:59:59.000-06:00",
"expires_at": null,
"renew_by": null,
"required": true,
"score": 0,
"time_remaining": 7,
"current_position": 1,
"furthest_progress": 0.1429,
"quiz_positions": [
2,
3,
4,
5,
6,
7
],
"direct_enrollment": true,
"max_quiz_attempts": null,
"attempts_count": 1,
"inactive": null,
"program": null,
"programs": [],
"in_completed_program": false,
"external_id": null,
"estimated_time": 7,
"passing_threshold": 80,
"has_certificate": false,
"course_type": "bridge",
"slide_count": 7,
"attachments_count": 0,
"attachments_count_author": 1,
"third_party_course_id": null,
"open_book": false,
"continuing_education_credits": null,
"features": [
"has_quizzes"
]
},
"tags": []
},
{
"id": "6301",
"enrollable_id": "1",
"enrollable_type": "ProgramEnrollment",
"learnable_id": "1",
"learnable_type": "Program",
"title": "IamaProgram",
"description": null,
"state": "active",
"completed_at": null,
"created_at": "2018-08-27T13:01:07.383-06:00",
"archived_at": null,
"permanently_failed": false,
"data": {
"required": true,
"current_course": {
"id": 19,
"title": "abcde",
"state": "created",
"end_at": "2018-09-03T23:59:59.999-06:00",
"expires_at": null,
"renew_by": null,
"required": true,
"score": 0,
"estimated_time": 2,
"time_remaining": 2,
"passing_threshold": 80,
"has_certificate": null,
"course_type": "bridge",
"slide_count": 2,
"attachments_count": 0,
"current_position": 0,
"furthest_progress": 0,
"learnable_type": "CourseTemplate"
},
"end_at": null,
"expires_at": null,
"furthest_progress": 0,
"inactive": null,
"item_count": 2,
"item_counts": [
{
"item_type": "CourseTemplate",
"count": 2
}
],
"program_index": 1,
"has_certificate": false,
"pending_approval_item_count": 0,
"pending_approval_items": [],
"features": [
"has_quizzes"
]
},
"tags": []
},
{
"id": "6300",
"enrollable_id": "1",
"enrollable_type": "TaskEnrollment",
"learnable_id": "1",
"learnable_type": "Task",
"title": "IamaCheckpoint",
"description": "",
"state": "created",
"completed_at": null,
"created_at": "2018-08-27T12:59:42.541-06:00",
"archived_at": null,
"permanently_failed": false,
"data": {
"requires_approval": false,
"requires_evidence": false,
"direct_enrollment": true,
"required": true,
"program": null,
"programs": [],
"in_completed_program": false,
"end_at": "2018-09-03T23:59:59.999-06:00",
"inactive": null,
"attachments_count": 0,
"attachments_count_author": 0,
"has_certificate": false
},
"tags": []
},
{
"id": "3450",
"enrollable_id": "3450",
"enrollable_type": "Enrollment",
"learnable_id": "4",
"learnable_type": "CourseTemplate",
"title": "Science 101",
"description": null,
"state": "complete",
"completed_at": "2018-08-27T12:37:13.365-06:00",
"created_at": "2017-04-10T16:26:36.368-06:00",
"archived_at": null,
"permanently_failed": false,
"data": {
"end_at": "2017-04-17T23:59:59.000-06:00",
"expires_at": null,
"renew_by": null,
"required": true,
"score": 100,
"time_remaining": 0,
"current_position": 0,
"furthest_progress": 1,
"quiz_positions": [],
"direct_enrollment": true,
"max_quiz_attempts": null,
"attempts_count": 1,
"inactive": null,
"program": null,
"programs": [],
"in_completed_program": false,
"external_id": null,
"estimated_time": 4,
"passing_threshold": 80,
"has_certificate": false,
"course_type": "bridge",
"slide_count": 4,
"attachments_count": 0,
"attachments_count_author": 0,
"third_party_course_id": null,
"open_book": null,
"continuing_education_credits": null,
"features": []
},
"tags": []
}
],
"meta": {}
}`
I just want to get all the courses (learnable_id) which are
State = Created
learnable_type = CourseTemplate
Once I get all the learnable_id which met above condition then I can return random number from that array.
How do I get this?
Thanks in advance.
You can use JSON path to extract json key values by applying required filters
Add a JSON extractor as a child of your request where you are getting above respone.
use the following configuration in JSON extractor
Json path Expression : $..[?(#.learnable_type=='CourseTemplate' && #.state == 'created')].learnable_id
match no : 0 (This will return a random matach from the possible matches in JMeter
as shown below
Debug Sampler Result :
More info :
Extracting variables
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import net.minidev.json.parser.JSONParser;
import org.apache.commons.lang.StringUtils;
import java.util.List;
import java.util.ArrayList;
import java.util.Random;
//Get Store total count
int totalLearningItems = StringUtils.countMatches(new String(data), "enrollable_id");
log.info("Total Number of Learning Items are: " + totalLearningItems);
Random rand = new Random();
if (totalLearningItems > 0) {
//Check for Fulfilment type is "Pickup"
String jsonString = new String(data);
JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
JSONObject learning_items = (JSONObject) parser.parse(data);
JSONArray learningArray = (JSONArray) learning_items.get("learning_items");
String learningItemId;
courseList = new ArrayList();
programList = new ArrayList();
taskList = new ArrayList();
for (int i=0; i<learningArray.size(); i++) {
if(learningArray.get(i).getAsString("state").equals("created") || learningArray.get(i).getAsString("state").equals("active")) {
if(learningArray.get(i).getAsString("learnable_type").equals("CourseTemplate")){
courseList.add(learningArray.get(i).getAsString("learnable_id"));
} else if (learningArray.get(i).getAsString("learnable_type").equals("Program")) {
programList.add(learningArray.get(i).getAsString("learnable_id"));
} else if (learningArray.get(i).getAsString("learnable_type").equals("Task")) {
taskList.add(learningArray.get(i).getAsString("learnable_id"));
}
}
}
if(courseList.size() > 0) {
vars.put("courseID", courseList.get(new Random().nextInt(courseList.size())));
} else if (programList.size() > 0) {
vars.put("programID", programList.get(new Random().nextInt(programList.size())));
} else if(taskList.size() > 0) {
vars.put("taskID", taskList.get(new Random().nextInt(taskList.size())));
}
}
I want to extract some data and store it as JMeter variables of a previous sampler response. In my response, there are many, so called, attributes which have a formulaName, a definitionId and a id. I want to find a specific attribute via the formulaName ("formulaName": "F1"; defined is user defined variables) and get it's definitionId and id and store them in a variable like attributeF1DefinitionId and attributeF1Id.
On the bottom of the question a complete JSON response can be found, which was not shortened to better describe my problem.
{
"resultType": "OK",
"messages": null,
"results": {
"data": {
"actionData": {
"actionId": "00000000-0000-0000-0000-000000000000",
"modelId": "00000000-0000-0000-0000-000000000000",
"isNew": false,
"isReadOnly": false,
"includeDisplayObjectsInTabVisibility": true,
"preselectedTabId": "00000000-0000-0000-0000-000000000000",
"elementId": "AM100000001",
"localizedName": "AM100000001Action",
"headerLayout": {
"fitToAvailableWidth": true,
"fillingColumnIndex0Based": 0,
"fitToAvailableHeight": false,
"fillingRowIndex0Based": null,
"attributes": null
"tabs": [
{
"id": "00000000-0000-0000-0000-000000000000",
"formulaName": "TD1",
"name": "Description",
"nameAdditionalInfos": null,
"dynamicLayout": {
"fitToAvailableWidth": false,
"fillingColumnIndex0Based": null,
"fitToAvailableHeight": false,
"fillingRowIndex0Based": null,
"attributes": [
{
"id": "10000000-0000-0000-0000-000000000001",
"name": "Attribute Number 1",
"formulaName": "F1",
"definitionId": "10000000-0000-0000-0000-000000000001",
"isHidden": false
},
{
"id": "20000000-0000-0000-0000-000000000002",
"name": "Attribute Number 2",
"formulaName": "F2",
"definitionId": "20000000-0000-0000-0000-000000000002",
"isHidden": false
},
......
Any approaches are appreciated, where I can automate this extraction in the next step. What I actually want to do, is to extract almost all definitionIds and ids of all attributes (found by their formulaName) and generate use defined variables for them. The formula names are held in a "User defined variables" - Set and I found a way to iterate through it with groovy.
My approach was with a JSR223 - groovy post processor inside the request sampler which loads the data and has the response seen above.
But im stuck, with the filtering for my specific formulaName.
import groovy.json.*;
import org.apache.jmeter.threads.JMeterVariables;
def response = prev.getResponseDataAsString();
def json = new JsonSlurper().parseText(response)
def allAttributes = json.results.data.actionData.tabs.dynamicLayout.attributes;
Complete JSON response:
{
"resultType": "OK",
"messages": null,
"results": {
"data": {
"actionData": {
"actionId": "627292b8-5854-4413-bd3c-7bc4a683f58d",
"modelId": "da5433d1-74f9-43e4-8a98-92c8eb9dcead",
"isReadOnly": false,
"preselectedTabId": "14ff3d76-532d-47a6-bb85-5e48b0e7cab9",
"elementId": "AM200000001",
"localizedName": "AM200000001Action",
"tabs": [
{
"id": "14ff3d76-532d-47a6-bb85-5e48b0e7cab9",
"formulaName": "TD2",
"name": "Description",
"clientId": "627292b8-5854-4413-bd3c-7bc4a683f58d_14ff3d76-532d-47a6-bb85-5e48b0e7cab9",
"nameAdditionalInfos": null,
"dynamicLayout": {
"fitToAvailableWidth": false,
"fillingColumnIndex0Based": null,
"fitToAvailableHeight": false,
"fillingRowIndex0Based": null,
"attributes": [
{
"id": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b",
"name": "F1 attribute name",
"formulaName": "F1",
"definitionId": "1dc065a6-f071-4547-835b-603aff165754",
"isHidden": false,
"isReadOnly": false,
"isMandatory": true,
"label": {
"settings": {
"bold": false,
"underline": false,
"color": "#000000",
"fontSize": null,
"allowTextWrap": true
},
"text": "F1 attribute name",
"colonPosition": 6,
"referedClientId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b_Value",
"clientId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b_Label",
"layout": {
"positionHorizontal": 3,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeLabelDefault",
"parameters": null
}
},
"mandatorySign": {
"clientId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b_MandatorySign",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeMandatorySignDefault",
"parameters": null
}
},
"documentation": {
"documentations": [
{
"id": "a2a4fb71-9662-44e3-9279-b4692f9ca8f1",
"name": "Attribute documentation",
"type": 2
}
],
"clientId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b_Documentation",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeDocumentationSignDefault",
"parameters": null
}
},
"value": {
"width": 570,
"options": [
{
"id": "402e48f4-a313-4869-9355-91b120a93849",
"text": "Planned",
"cascadingParentItemIds": []
},
{
"id": "f68bc4d8-ef25-4f02-acf4-bc20cbe45ab0",
"text": "Implemented",
"cascadingParentItemIds": []
}
],
"cascadingParentAttributeId": null,
"allowsNoValue": true,
"cascadingParentInitialValue": null,
"value": "402e48f4-a313-4869-9355-91b120a93849",
"attributeType": "ActionAttributeListSingleEntity",
"isDirty": false,
"clientId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b_Value",
"layout": {
"positionHorizontal": 1,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeSingleSelectListDefault",
"parameters": null
}
},
"dependencies": []
},
{
"id": "c75171ee-bd2f-4396-828e-0f909ae538ed",
"name": "F2 attribute name",
"formulaName": "F2",
"definitionId": "886e8d59-deb5-4725-8080-9033feacb6d3",
"isHidden": false,
"isReadOnly": false,
"isMandatory": true,
"label": {
"settings": {
"bold": false,
"underline": false,
"color": "#000000",
"fontSize": null,
"allowTextWrap": true
},
"text": "F2 attribute name",
"colonPosition": 6,
"referedClientId": "c75171ee-bd2f-4396-828e-0f909ae538ed_Value",
"clientId": "c75171ee-bd2f-4396-828e-0f909ae538ed_Label",
"layout": {
"positionHorizontal": 3,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeLabelDefault",
"parameters": null
}
},
"mandatorySign": {
"clientId": "c75171ee-bd2f-4396-828e-0f909ae538ed_MandatorySign",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeMandatorySignDefault",
"parameters": null
}
},
"documentation": {
"documentations": [
{
"id": "734d1c1e-0b35-46f3-9580-7f0a31a8201b",
"name": "Attribute documentation",
"type": 2
}
],
"clientId": "c75171ee-bd2f-4396-828e-0f909ae538ed_Documentation",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeDocumentationSignDefault",
"parameters": null
}
},
"value": {
"width": 570,
"options": [
{
"id": "3231d235-36e3-497a-b244-f1ccd3e4a585",
"text": "None",
"cascadingParentItemIds": [
"402e48f4-a313-4869-9355-91b120a93849",
"f68bc4d8-ef25-4f02-acf4-bc20cbe45ab0"
]
},
{
"id": "1b2e9695-0945-4724-85cb-70b4d55bcaf3",
"text": "Weak",
"cascadingParentItemIds": [
"f68bc4d8-ef25-4f02-acf4-bc20cbe45ab0"
]
},
{
"id": "b89239d8-2bad-48ad-b3b9-f1426b0b5b8c",
"text": "Noticeable",
"cascadingParentItemIds": [
"f68bc4d8-ef25-4f02-acf4-bc20cbe45ab0"
]
},
{
"id": "8bc090f5-17c1-4040-9a16-2d4a9b609c94",
"text": "Strong",
"cascadingParentItemIds": [
"f68bc4d8-ef25-4f02-acf4-bc20cbe45ab0"
]
},
{
"id": "4cdee469-9524-4dde-8e24-a878ea8d2138",
"text": "Very strong",
"cascadingParentItemIds": [
"f68bc4d8-ef25-4f02-acf4-bc20cbe45ab0"
]
}
],
"cascadingParentAttributeId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b",
"allowsNoValue": true,
"cascadingParentInitialValue": [
"402e48f4-a313-4869-9355-91b120a93849"
],
"value": "3231d235-36e3-497a-b244-f1ccd3e4a585",
"attributeType": "ActionAttributeListSingleEntity",
"isDirty": false,
"clientId": "c75171ee-bd2f-4396-828e-0f909ae538ed_Value",
"layout": {
"positionHorizontal": 1,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeSingleSelectListDefault",
"parameters": null
}
},
"dependencies": [
{
"requiresFullUpdate": false,
"sourceAttributeId": "ca25c1bc-5528-4730-8cc5-3a3c2ca4428b",
"targetAttributeId": "c75171ee-bd2f-4396-828e-0f909ae538ed"
}
]
},
{
"id": "16f18829-e905-498a-8c28-2d29fc2e7b8b",
"name": "F3 attribute name",
"formulaName": "F3",
"definitionId": "9aef853b-f4c3-440d-9c32-6d9a13835033",
"isHidden": false,
"isReadOnly": false,
"isMandatory": true,
"label": {
"settings": {
"bold": false,
"underline": false,
"color": "#000000",
"fontSize": null,
"allowTextWrap": true
},
"text": "F3 attribute name",
"colonPosition": 6,
"referedClientId": "16f18829-e905-498a-8c28-2d29fc2e7b8b_Value",
"clientId": "16f18829-e905-498a-8c28-2d29fc2e7b8b_Label",
"layout": {
"positionHorizontal": 3,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeLabelDefault",
"parameters": null
}
},
"mandatorySign": {
"clientId": "16f18829-e905-498a-8c28-2d29fc2e7b8b_MandatorySign",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeMandatorySignDefault",
"parameters": null
}
},
"documentation": {
"documentations": [
{
"id": "096f02b4-2570-47b2-a346-c27c5102ceda",
"name": "Attribute documentation",
"type": 2
}
],
"clientId": "16f18829-e905-498a-8c28-2d29fc2e7b8b_Documentation",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeDocumentationSignDefault",
"parameters": null
}
},
"value": {
"width": 570,
"rows": 4,
"maxLength": 30000,
"searchInfo": null,
"value": "Textattribute value was changed! ",
"attributeType": "ActionAttributeTextEntity",
"isDirty": false,
"clientId": "16f18829-e905-498a-8c28-2d29fc2e7b8b_Value",
"layout": {
"positionHorizontal": 1,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeTextboxDefault",
"parameters": null
}
},
"dependencies": []
}
],
"displayObjects": []
}
},
{
"id": "e72e24ab-0ebd-4dd8-bf7b-4586dbc50da4",
"formulaName": "TD1",
"name": "Remarks",
"clientId": "627292b8-5854-4413-bd3c-7bc4a683f58d_e72e24ab-0ebd-4dd8-bf7b-4586dbc50da4",
"nameAdditionalInfos": null,
"dynamicLayout": {
"fitToAvailableWidth": false,
"fillingColumnIndex0Based": null,
"fitToAvailableHeight": false,
"fillingRowIndex0Based": null,
"attributes": [
{
"id": "1ef375a3-fc5b-47dc-8b32-4a106cfa2987",
"name": "Remark attribute 1",
"formulaName": "R1",
"definitionId": "9709e796-3be7-49e5-a638-ed9de027b680",
"isHidden": false,
"isReadOnly": true,
"isMandatory": false,
"label": {
"settings": {
"bold": false,
"underline": false,
"color": "#000000",
"fontSize": null,
"allowTextWrap": true
},
"text": "Remark attribute 1",
"colonPosition": 6,
"referedClientId": "1ef375a3-fc5b-47dc-8b32-4a106cfa2987_Value",
"clientId": "1ef375a3-fc5b-47dc-8b32-4a106cfa2987_Label",
"layout": {
"positionHorizontal": 3,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeLabelDefault",
"parameters": null
}
},
"mandatorySign": {
"clientId": "1ef375a3-fc5b-47dc-8b32-4a106cfa2987_MandatorySign",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeMandatorySignDefault",
"parameters": null
}
},
"documentation": {
"documentations": [
{
"id": "d31bb13b-1f12-4f43-8ec4-d91fc405b3ae",
"name": "Attribute documentation",
"type": 2
}
],
"clientId": "1ef375a3-fc5b-47dc-8b32-4a106cfa2987_Documentation",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeDocumentationSignDefault",
"parameters": null
}
},
"value": {
"width": 570,
"rows": 4,
"maxLength": 30000,
"searchInfo": null,
"value": "",
"attributeType": "ActionAttributeTextEntity",
"isDirty": false,
"clientId": "1ef375a3-fc5b-47dc-8b32-4a106cfa2987_Value",
"layout": {
"positionHorizontal": 1,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeTextboxDefault",
"parameters": null
}
},
"dependencies": []
},
{
"id": "379d5451-e5af-42f8-b8b8-52b7f0953261",
"name": "Remark attribute 2",
"formulaName": "R2",
"definitionId": "ba03b62d-bcc1-40c7-9df1-e976151821a2",
"isHidden": false,
"isReadOnly": true,
"isMandatory": false,
"label": {
"settings": {
"bold": false,
"underline": false,
"color": "#000000",
"fontSize": null,
"allowTextWrap": true
},
"text": "Remark attribute 1",
"colonPosition": 6,
"referedClientId": "379d5451-e5af-42f8-b8b8-52b7f0953261_Value",
"clientId": "379d5451-e5af-42f8-b8b8-52b7f0953261_Label",
"layout": {
"positionHorizontal": 3,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeLabelDefault",
"parameters": null
}
},
"mandatorySign": {
"clientId": "379d5451-e5af-42f8-b8b8-52b7f0953261_MandatorySign",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeMandatorySignDefault",
"parameters": null
}
},
"documentation": {
"documentations": [
{
"id": "129e84fe-0d76-4f8b-b5aa-e80e452998bd",
"name": "Attribute documentation",
"type": 2
}
],
"clientId": "379d5451-e5af-42f8-b8b8-52b7f0953261_Documentation",
"layout": {
"positionHorizontal": 2,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeDocumentationSignDefault",
"parameters": null
}
},
"value": {
"width": 570,
"rows": 4,
"maxLength": 30000,
"searchInfo": null,
"value": "",
"attributeType": "ActionAttributeTextEntity",
"isDirty": false,
"clientId": "379d5451-e5af-42f8-b8b8-52b7f0953261_Value",
"layout": {
"positionHorizontal": 1,
"positionVertical": 1
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeTextboxDefault",
"parameters": null
}
},
"dependencies": []
}
],
"displayObjects": []
}
}
],
"footerLayout": {
"fitToAvailableWidth": true,
"fillingColumnIndex0Based": 2,
"fitToAvailableHeight": false,
"fillingRowIndex0Based": null,
"attributes": [
{
"id": "AuditComment",
"name": null,
"formulaName": "AuditComment",
"definitionId": "AuditComment",
"isHidden": false,
"isReadOnly": false,
"isMandatory": false,
"label": {
"settings": {
"bold": false,
"underline": false,
"color": "#000000",
"fontSize": null,
"allowTextWrap": false
},
"text": "Audit-Trail Comment",
"colonPosition": 7,
"referedClientId": "627292b8-5854-4413-bd3c-7bc4a683f58d_EndDateValue",
"clientId": "627292b8-5854-4413-bd3c-7bc4a683f58d_EndDateLabel",
"layout": {
"positionHorizontal": 3,
"positionVertical": 2
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeLabelDefault",
"parameters": null
}
},
"mandatorySign": {
"clientId": "627292b8-5854-4413-bd3c-7bc4a683f58d_EndDateMandatorySign",
"layout": {
"positionHorizontal": 2,
"positionVertical": 2
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeMandatorySignDefault",
"parameters": null
}
},
"documentation": null,
"value": {
"width": null,
"rows": 1,
"maxLength": null,
"searchInfo": null,
"value": "",
"attributeType": "ActionAttributeTextEntity",
"isDirty": false,
"clientId": "627292b8-5854-4413-bd3c-7bc4a683f58d_EndDateValue",
"layout": {
"positionHorizontal": 1,
"positionVertical": 2
},
"displayWidget": {
"identifier": "ActionDetailDisplayTypeTextboxDefault",
"parameters": null
}
},
"dependencies": null
}
],
"displayObjects": null
}
},
"linkedActions": null,
"documentations": null,
"approvals": null
}
}
}
I believe you can do it much easier using JSON Extractor, for example you can get id attribute where "formulaName" is "F1" using the following simple JSON Path query:
$..[?(#.formulaName == 'F1')].id
Similarly for definitionId, just change the above JSON Path query to match it:
$..[?(#.formulaName == 'F1')].definitionId
References:
JsonPath Operators
Advanced Usage of the JSON Path Extractor in JMeter
Groovy approach:
import groovy.json.JsonSlurper
def response = prev.getResponseDataAsString()
def json = new JsonSlurper().parseText(response)
def allAttributes = json.results.data.actionData.headerLayout.tabs[0].dynamicLayout.attributes
allAttributes.each { attribute ->
attribute.each { k, v -> log.info("${k}:${v}") }
}
With getJsonResponseString() returning a string with the json response data as specified in the question ("complete json response"), the below groovy code:
import groovy.json.*;
def data = getJsonResponseString()
def json = new JsonSlurper().parseText(data)
def attribute = json.results.data.actionData.tabs.dynamicLayout.attributes.first().find { attribute ->
attribute.formulaName == "F1"
}
if (!attribute) {
println "No attribute with formulaName F1 found!"
} else {
println "Results for 'F1': "
println " definitionId: ${attribute.definitionId}"
println " id: ${attribute.id}"
}
prints:
Results for 'F1':
definitionId: 1dc065a6-f071-4547-835b-603aff165754
id: ca25c1bc-5528-4730-8cc5-3a3c2ca4428b
the json object in the above code should be equivalent to the json object in your sample code.
i want to get access of "uuid" everytime,which is two times present in this code and also access to "cloud_uuid". the body is something like below:
{
"computes": [{
"uuid": "110c607a-231c-4724-be7f-db5ed388158",
"name": "9.4.98.33",
"description": null,
"version": "1.0",
"type": "compute",
"number_of_vms": 0,
"status": "ACTIVE",
"provisioning_status": {
"status": "COMPLETED",
"started_at": "",
"updated_at": "",
"status_data": null
},
"health_status": {
"status": "OK",
"alerts": [],
"updated_at": "2014-07-11T17:09:12.194000"
},
"compliance_status": {
"compliance_reasons": null,
"is_compliant": true,
"updated_at": null
},
"run_priority_order": null,
"created": "2014-07-11T16:01:32.837821",
"updated": "2014-07-11T17:08:16.031838",
"capability_categories": {
"v": [{
"name_key": "",
"description_key": "",
"version": "0",
"hidden": t,
"priority": 1,
"name_nls": "",
"description_nls": ""
}],
"monitoring": [{
"name_key": "m",
"description_key": null,
"version": "1.0",
"hidden": true,
"priority": 100,
"name_nls": "monitoring",
"description_nls": null
}],
"scheduler": [{
"name_key": "",
"description_key": null,
"version": "1.0",
"hidden": false,
"priority": 20,
"name_nls": "",
"description_nls": null
}],
"network": [{
"name_key": "",
"description_key": "",
"version": "1.0",
"hidden": false,
"priority": 10,
"name_nls": "",
"description_nls": ""
}]
},
"links": [{
"href": "",
"rel": "self"
}, {
"href": "",
"rel": "bookmark"
}],
"cloud_uuid": "b603e16e-38a6-435e-9359-79c27fee93a",
"operating_system_uuid": "70f605e7-6512-49b4-833c-b25d47823a4"
}, {
"uuid": "7383f4a5-dc0a-420b-806c-abbd49c1655a",
"name": "9.4.193.20",
"description": null,
"version": "1.0",
"type": "compute"
could you help with below,i tried the code as answered in comment:
suppose body is "clouds" instead of "computes"
i tried for getting cloud_uuid with something like:cloud_uuid = ((e['cloud_uuid'] for e in dict['clouds'] if e['name'] == name_to_find), None)
it throws error->
cloud_uuid = ((e['cloud_uuid'] for e in dict['clouds'] if e['name'] ==
name_to_find), None) TypeError: 'type' object is unsubscriptable
In python it is very simple:
[(e['uuid'], e['cloud_uuid']) for e in dict['computes']]
Edit:
It looks like I overlooked a pair square braces. Try:
[(_['computes'][0]['uuid'], _['cloud_uuid']) for _ in data]