Related
Greetings for the day!
how to get "created" value if "toString" value is Code Review from below json code.
Json code:-
{
"expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations",
"id": "562940",
"self": "https://example/rest/api/2/issue/562940",
"key": "TPR-13098",
"fields": {
"customfield_17384": null,
"customfield_17379": null,
"customfield_17378": null,
"labels": [
],
"customfield_15505": null,
"issuelinks": [
],
"customfield_11709": null,
"assignee": {
"self": "https://example/rest/api/2/user?username=example",
"name": "example",
"key": "example",
"emailAddress": "example#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?ownerId=example&avatarId=12908",
"24x24": "https://example/secure/useravatar?size=small&ownerId=example&avatarId=12908",
"16x16": "https://example/secure/useravatar?size=xsmall&ownerId=example&avatarId=12908",
"32x32": "https://example/secure/useravatar?size=medium&ownerId=example&avatarId=12908"
},
"displayName": "example",
"active": true,
"timeZone": "Asia/Kolkata"
},
"components": [
{
"self": "https://example/rest/api/2/component/17139",
"id": "17139",
"name": "Others"
}
],
"customfield_17366": null,
"customfield_11935": [
{
"self": "https://example/rest/api/2/user?username=testuser",
"name": "testuser",
"key": "testuser",
"emailAddress": "testuser#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?avatarId=15907",
"24x24": "https://example/secure/useravatar?size=small&avatarId=15907",
"16x16": "https://example/secure/useravatar?size=xsmall&avatarId=15907",
"32x32": "https://example/secure/useravatar?size=medium&avatarId=15907"
},
"displayName": "testuser",
"active": true,
"timeZone": "Asia/Kolkata"
}
],
"customfield_11937": null,
"customfield_17351": "2021-06-30",
"subtasks": [
],
"customfield_17352": null,
"customfield_17359": null,
"reporter": {
"self": "https://example/rest/api/2/user?username=testuser",
"name": "testuser",
"key": "testuser",
"emailAddress": "testuser#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?avatarId=15907",
"24x24": "https://example/secure/useravatar?size=small&avatarId=15907",
"16x16": "https://example/secure/useravatar?size=xsmall&avatarId=15907",
"32x32": "https://example/secure/useravatar?size=medium&avatarId=15907"
},
"displayName": "testuser",
"active": true,
"timeZone": "Asia/Kolkata"
},
"customfield_17357": null,
"customfield_16700": null,
"customfield_11920": null,
"customfield_11922": null,
"progress": {
"progress": 0,
"total": 0
},
"worklog": {
"startAt": 0,
"maxResults": 20,
"total": 0,
"worklogs": [
]
},
"issuetype": {
"self": "https://example/rest/api/2/issuetype/12506",
"id": "12506",
"description": "",
"iconUrl": "https://example/secure/viewavatar?size=xsmall&avatarId=10306&avatarType=issuetype",
"name": "Work Item",
"subtask": false,
"avatarId": 10306
},
"customfield_17102": null,
"customfield_17347": null,
"project": {
"self": "https://example/rest/api/2/project/14309",
"id": "14309",
"key": "TPR",
"name": "TallyPrime",
"projectTypeKey": "software",
"avatarUrls": {
"48x48": "https://example/secure/projectavatar?avatarId=10703",
"24x24": "https://example/secure/projectavatar?size=small&avatarId=10703",
"16x16": "https://example/secure/projectavatar?size=xsmall&avatarId=10703",
"32x32": "https://example/secure/projectavatar?size=medium&avatarId=10703"
}
},
"customfield_17346": null,
"customfield_17103": null,
"customfield_17345": "-",
"customfield_15602": null,
"customfield_11486": null,
"customfield_15600": null,
"customfield_15601": null,
"customfield_16806": null,
"customfield_16804": null,
"customfield_11910": null,
"customfield_16803": null,
"customfield_11913": "2021-06-28",
"customfield_11912": null,
"customfield_11915": "2021-06-28",
"resolutiondate": null,
"customfield_11914": null,
"watches": {
"self": "https://example/rest/api/2/issue/TPR-13098/watchers",
"watchCount": 1,
"isWatching": false
},
"customfield_16002": null,
"customfield_17333": null,
"customfield_17331": 0.0,
"customfield_17330": null,
"customfield_16006": null,
"customfield_16005": null,
"customfield_16003": null,
"customfield_16802": null,
"customfield_16009": null,
"customfield_16801": null,
"customfield_16800": null,
"customfield_17339": null,
"customfield_16007": null,
"customfield_17338": null,
"updated": "2021-06-29T17:40:13.000+0530",
"customfield_17322": null,
"customfield_17321": null,
"timeoriginalestimate": null,
"customfield_17326": null,
"description": "Clean up of JsonElem::GetOwnName as it is duplicate of JsonElem::GetKey.",
"customfield_10010": "0|i2he8j:",
"customfield_17323": null,
"customfield_11344": 0.0,
"customfield_17329": null,
"timetracking": {
},
"customfield_15700": {
"self": "https://example/rest/api/2/customFieldOption/16104",
"value": "Thank you",
"id": "16104"
},
"customfield_10005": null,
"customfield_14726": null,
"customfield_10006": null,
"customfield_14724": null,
"customfield_14725": null,
"summary": "Clean up of GetOwnName from JsonElem class",
"customfield_16101": null,
"customfield_17311": null,
"customfield_16100": null,
"customfield_17310": null,
"customfield_16103": null,
"customfield_16102": null,
"customfield_17312": null,
"customfield_14722": null,
"customfield_14723": null,
"customfield_17318": null,
"customfield_14721": null,
"customfield_11204": null,
"customfield_11205": "0.0",
"environment": null,
"customfield_11206": 0.0,
"customfield_10118": null,
"duedate": null,
"comment": {
"comments": [
],
"maxResults": 0,
"total": 0,
"startAt": 0
},
"customfield_17300": null,
"customfield_17304": "3.Coding",
"customfield_17303": null,
"fixVersions": [
{
"self": "https://example/rest/api/2/version/18013",
"id": "18013",
"description": "This is for Release B1 of GST Revamp planned as part of TallyPrime",
"name": "TallyPrime Release 3.0",
"archived": false,
"released": false
}
],
"customfield_17301": {
"self": "https://example/rest/api/2/customFieldOption/18133",
"value": "Client",
"id": "18133"
},
"customfield_15800": null,
"customfield_17307": {
"self": "https://example/rest/api/2/user?username=example",
"name": "example",
"key": "example",
"emailAddress": "example#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?ownerId=example&avatarId=12908",
"24x24": "https://example/secure/useravatar?size=small&ownerId=example&avatarId=12908",
"16x16": "https://example/secure/useravatar?size=xsmall&ownerId=example&avatarId=12908",
"32x32": "https://example/secure/useravatar?size=medium&ownerId=example&avatarId=12908"
},
"displayName": "example",
"active": true,
"timeZone": "Asia/Kolkata"
},
"customfield_17305": null,
"customfield_14704": null,
"customfield_14705": null,
"timeestimate": null,
"status": {
"self": "https://example/rest/api/2/status/12606",
"description": "",
"iconUrl": "https://example/images/icons/statuses/generic.png",
"name": "Code Review",
"id": "12606",
"statusCategory": {
"self": "https://example/rest/api/2/statuscategory/4",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
}
},
"customfield_17403": null,
"customfield_17401": null,
"customfield_15102": {
"self": "https://example/rest/api/2/customFieldOption/18132",
"value": "Code Improvement",
"id": "18132"
},
"customfield_17400": null,
"customfield_15900": null,
"customfield_17406": null,
"customfield_17405": null,
"customfield_17404": null,
"customfield_14802": null,
"aggregatetimeestimate": null,
"creator": {
"self": "https://example/rest/api/2/user?username=testuser",
"name": "testuser",
"key": "testuser",
"emailAddress": "testuser#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?avatarId=15907",
"24x24": "https://example/secure/useravatar?size=small&avatarId=15907",
"16x16": "https://example/secure/useravatar?size=xsmall&avatarId=15907",
"32x32": "https://example/secure/useravatar?size=medium&avatarId=15907"
},
"displayName": "testuser",
"active": true,
"timeZone": "Asia/Kolkata"
},
"aggregateprogress": {
"progress": 0,
"total": 0
},
"timespent": null,
"customfield_15202": [
],
"customfield_15203": null,
"customfield_15200": null,
"customfield_15201": null,
"aggregatetimespent": null,
"customfield_15204": null,
"workratio": -1,
"customfield_15306": null,
"customfield_15303": null,
"attachment": [
],
"customfield_10527": null,
"customfield_10518": null
},
"changelog": {
"startAt": 0,
"maxResults": 4,
"total": 4,
"histories": [
{
"id": "3818773",
"author": {
"self": "https://example/rest/api/2/user?username=testuser",
"name": "testuser",
"key": "testuser",
"emailAddress": "testuser#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?avatarId=15907",
"24x24": "https://example/secure/useravatar?size=small&avatarId=15907",
"16x16": "https://example/secure/useravatar?size=xsmall&avatarId=15907",
"32x32": "https://example/secure/useravatar?size=medium&avatarId=15907"
},
"displayName": "testuser",
"active": true,
"timeZone": "Asia/Kolkata"
},
"created": "2021-06-28T16:34:02.000+0530",
"items": [
{
"field": "status",
"fieldtype": "jira",
"from": "10114",
"fromString": "New",
"to": "12605",
"toString": "Coding"
}
]
},
{
"id": "3818870",
"author": {
"self": "https://example/rest/api/2/user?username=testuser",
"name": "testuser",
"key": "testuser",
"emailAddress": "testuser#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?avatarId=15907",
"24x24": "https://example/secure/useravatar?size=small&avatarId=15907",
"16x16": "https://example/secure/useravatar?size=xsmall&avatarId=15907",
"32x32": "https://example/secure/useravatar?size=medium&avatarId=15907"
},
"displayName": "testuser",
"active": true,
"timeZone": "Asia/Kolkata"
},
"created": "2021-06-28T17:23:44.000+0530",
"items": [
{
"field": "status",
"fieldtype": "jira",
"from": "12605",
"fromString": "Coding",
"to": "12606",
"toString": "Code Review"
}
]
},
{
"id": "3820419",
"author": {
"self": "https://example/rest/api/2/user?username=example",
"name": "example",
"key": "example",
"emailAddress": "example#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?ownerId=example&avatarId=12908",
"24x24": "https://example/secure/useravatar?size=small&ownerId=example&avatarId=12908",
"16x16": "https://example/secure/useravatar?size=xsmall&ownerId=example&avatarId=12908",
"32x32": "https://example/secure/useravatar?size=medium&ownerId=example&avatarId=12908"
},
"displayName": "example",
"active": true,
"timeZone": "Asia/Kolkata"
},
"created": "2021-06-29T17:40:12.000+0530",
"items": [
{
"field": "Coding Due Date",
"fieldtype": "custom",
"from": null,
"fromString": null,
"to": "2021-06-30",
"toString": "30/Jun/21"
}
]
},
{
"id": "3820420",
"author": {
"self": "https://example/rest/api/2/user?username=example",
"name": "example",
"key": "example",
"emailAddress": "example#sample",
"avatarUrls": {
"48x48": "https://example/secure/useravatar?ownerId=example&avatarId=12908",
"24x24": "https://example/secure/useravatar?size=small&ownerId=example&avatarId=12908",
"16x16": "https://example/secure/useravatar?size=xsmall&ownerId=example&avatarId=12908",
"32x32": "https://example/secure/useravatar?size=medium&ownerId=example&avatarId=12908"
},
"displayName": "example",
"active": true,
"timeZone": "Asia/Kolkata"
},
"created": "2021-06-29T17:40:13.000+0530",
"items": [
{
"field": "assignee",
"fieldtype": "jira",
"from": "testuser",
"fromString": "testuser",
"to": "example",
"toString": "example"
}
]
}
]
}
}
..
| objects
| select(has("created") and any(.items[]; .toString == "Code Review"))
| .created
Research Effort
For future reference, please note that, since you've been a member of the SO community for over a year and have asked other questions, you should be familiar with the SO guidelines for asking appropriate questions. Apart from the "miminum reproducible example" guidelines already mentioned on this page, there should be some evidence of "research effort" as per
How much research effort is expected of Stack Overflow users?
I have an application where in there is a form which has all the controls like ( text box, dropdowns, list, text areas, checkbox, tables)
And all the data when it is saved it is saved as a json object and that object is stored in one of the column in the database.
Now I am automating this form and i would like to assert this page.
Approach taken so far :
From the UI page, captured all the data in a Dictionary object and then converted the same in the json object .
This is what it looks like
{
"AtRiskSchoolName": "11!!!!#############",
"PercentFreeReduced": "11.00",
"IsAtRiskSite": "Yes",
"Associated": "Non-Profit Center or Public Institution: Children or Adults",
"FacilityType": "Rented/Leased",
"SiteTypes": "Child",
"ParticipantXIXX": "1",
"ParticipantFree": "8",
"ParticipantReduced": "8",
"ParticipantPaid": "99",
"TraditionalMeals[0].Value1": "6:00am",
"TraditionalMeals[0].Value2": "6:30am",
"TraditionalMeals[0].Value3": "7:00am",
"TraditionalMeals[0].Value4": "7:30am",
"TraditionalMeals[1].Value1": "8:00am",
"TraditionalMeals[1].Value2": "8:30am",
"TraditionalMeals[1].Value3": "9:00am",
"TraditionalMeals[1].Value4": "9:30am",
"TraditionalMeals[2].Value1": "11:00am",
"TraditionalMeals[2].Value2": "11:30am",
"TraditionalMeals[2].Value3": "12:00pm",
"TraditionalMeals[2].Value4": "12:30pm"
}
And from the database captured the entire json object and then parsed it as json object.
Json object from the database looks like :-
{
"AlwaysOptional": false,
"Associated": "Non-Profit",
"AtRiskAreaEligibilityExpiryDate": "0001-01-01T00:00:00",
"AtRiskMeals": [{
"Address": null,
"Type": "Breakfast",
"Value1": "7:00am",
"Value2": "7:30am",
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Morning Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Lunch",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Afternoon Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Supper",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Evening Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}
],
"AtRiskSchoolName": "11!!!!#############",
"Ethnic": [{
"Address": null,
"Type": "Hispanic or Latino (Cuban, Mexican, Puerto Rican, South or Central American, or other Spanish culture or origin regardless of race.)",
"Value1": "1",
"Value2": "50.00",
"Value3": "50",
"Value4": null
}, {
"Address": null,
"Type": "Non-Hispanic or Non-Latino (All others, Irish, French, German, etc.)",
"Value1": "1",
"Value2": "50.00",
"Value3": "50",
"Value4": null
}, {
"Address": null,
"Type": "Total",
"Value1": "2",
"Value2": "100.00",
"Value3": "100.00",
"Value4": null
}
],
"FacilityType": "sitelease",
"IsAtRiskSite": true,
"ParticipantFree": 8,
"ParticipantPaid": 99,
"ParticipantReduced": 8,
"ParticipantXIXX": 1,
"PercentFreeReduced": 11.0,
"Racial": [{
"Address": null,
"Type": "White",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Black or African American",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "American Indian or Alaskan Native",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Asian",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Native Hawaiian",
"Value1": "1",
"Value2": "14.29",
"Value3": "40",
"Value4": null
}, {
"Address": null,
"Type": "Some Other Race",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Two or More Races",
"Value1": "1",
"Value2": "14.29",
"Value3": "10",
"Value4": null
}, {
"Address": null,
"Type": "Total",
"Value1": "7",
"Value2": "100.00",
"Value3": "100.00",
"Value4": null
}
],
"SiteIsRemoved": false,
"SiteName": "Beaver",
"SiteType": "Child",
"TotalEnrolled": 115,
"TraditionalMeals": [{
"Address": null,
"Type": "Breakfast",
"Value1": "6:00am",
"Value2": "6:30am",
"Value3": "7:00am",
"Value4": "7:30am"
}, {
"Address": null,
"Type": "Morning Snack",
"Value1": "8:00am",
"Value2": "8:30am",
"Value3": "9:00am",
"Value4": "9:30am"
}, {
"Address": null,
"Type": "Lunch",
"Value1": "11:00am",
"Value2": "11:30am",
"Value3": "12:00pm",
"Value4": "12:30pm"
}, {
"Address": null,
"Type": "Afternoon Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Supper",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}, {
"Address": null,
"Type": "Evening Snack",
"Value1": null,
"Value2": null,
"Value3": null,
"Value4": null
}
]
}
Problem comes when I am trying to assert both the objects, it is failing as the object from the database is having few elements as array meaning you can have multiple objects in the single json object.
And when I am trying to construct my Json object from the UI elements, I am not able to construct the array of elements.
Please advice if this is right approach to do the same.
I am using selenium with C#
Appreciate your help.
Found the solution by creating a Dictionary object from the UI and then converting the json object in Dictionary object.
I have following JSON file and would like to extract part of it:
{
"expand": "names,schema",
"issues": [
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"fields": {
"aggregateprogress": {
"progress": 0,
"total": 0
},
"aggregatetimeestimate": null,
"aggregatetimeoriginalestimate": null,
"aggregatetimespent": null,
"assignee": {
"active": true,
"avatarUrls": {
"16x16": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=16",
"24x24": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=24",
"32x32": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=32",
"48x48": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=48"
},
"displayName": "user",
"emailAddress": "user#company.com",
"key": "user",
"name": "user",
"self": "https://jira.corp.company.com/rest/api/2/user?username=dvucanovic",
"timeZone": "Europe/Belgrade"
},
"components": [],
"created": "2018-03-06T21:24:41.000+0000",
"creator": {
"active": true,
"avatarUrls": {
"16x16": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=16",
"24x24": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=24",
"32x32": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=32",
"48x48": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=48"
},
"displayName": "user",
"emailAddress": "user#company.com",
"key": "user",
"name": "user",
"self": "https://jira.corp.company.com/rest/api/2/user?username=dvucanovic",
"timeZone": "Europe/Belgrade"
},
"customfield_10000": null,
"customfield_10001": null,
"customfield_10002": null,
"customfield_10004": "0|i00uta:",
"customfield_10005": null,
"customfield_10006": null,
"customfield_10100": null,
"customfield_10101": [],
"customfield_10102": null,
"customfield_10103": null,
"customfield_10107": {
"id": "10400",
"self": "https://jira.corp.company.com/rest/api/2/customFieldOption/10400",
"value": "Hentsu Internal"
},
"customfield_10108": null,
"customfield_10200": null,
"customfield_10201": "2018-03-06",
"customfield_10202": "2018-03-06",
"customfield_10203": null,
"customfield_10204": null,
"customfield_10205": null,
"customfield_10206": null,
"customfield_10300": "com.atlassian.servicedesk.plugins.approvals.internal.customfield.ApprovalsCFValue#5e6792fb",
"customfield_10301": null,
"customfield_10302": null,
"customfield_10600": null,
"customfield_10700": null,
"customfield_11000": null,
"customfield_11001": null,
"customfield_11002": null,
"customfield_11003": null,
"customfield_11004": null,
"customfield_11005": null,
"customfield_11006": null,
"customfield_11007": null,
"customfield_11008": null,
"customfield_11009": null,
"customfield_11010": null,
"customfield_11011": null,
"customfield_11012": null,
"customfield_11013": null,
"customfield_11014": null,
"customfield_11015": null,
"customfield_11016": null,
"customfield_11017": null,
"customfield_11018": null,
"customfield_11019": null,
"customfield_11100": null,
"customfield_11101": null,
"customfield_11102": null,
"description": null,
"duedate": null,
"environment": null,
"fixVersions": [],
"issuelinks": [],
"issuetype": {
"avatarId": 10318,
"description": "A task that needs to be done.",
"iconUrl": "https://jira.corp.company.com/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype",
"id": "10100",
"name": "Task",
"self": "https://jira.corp.company.com/rest/api/2/issuetype/10100",
"subtask": false
},
"labels": [],
"lastViewed": "2018-03-06T21:31:34.315+0000",
"priority": {
"iconUrl": "https://jira.corp.company.com/images/icons/priorities/medium.svg",
"id": "3",
"name": "Medium",
"self": "https://jira.corp.company.com/rest/api/2/priority/3"
},
"progress": {
"progress": 0,
"total": 0
},
"project": {
"avatarUrls": {
"16x16": "https://jira.corp.company.com/secure/projectavatar?size=xsmall&pid=10001&avatarId=10201",
"24x24": "https://jira.corp.company.com/secure/projectavatar?size=small&pid=10001&avatarId=10201",
"32x32": "https://jira.corp.company.com/secure/projectavatar?size=medium&pid=10001&avatarId=10201",
"48x48": "https://jira.corp.company.com/secure/projectavatar?pid=10001&avatarId=10201"
},
"id": "10001",
"key": "TECH",
"name": "Technology",
"self": "https://jira.corp.company.com/rest/api/2/project/10001"
},
"reporter": {
"active": true,
"avatarUrls": {
"16x16": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=16",
"24x24": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=24",
"32x32": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=32",
"48x48": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=48"
},
"displayName": "user",
"emailAddress": "user#company.com",
"key": "user",
"name": "user",
"self": "https://jira.corp.company.com/rest/api/2/user?username=dvucanovic",
"timeZone": "Europe/Belgrade"
},
"resolution": null,
"resolutiondate": null,
"status": {
"description": "",
"iconUrl": "https://jira.corp.company.com/",
"id": "10000",
"name": "Backlog",
"self": "https://jira.corp.company.com/rest/api/2/status/10000",
"statusCategory": {
"colorName": "blue-gray",
"id": 2,
"key": "new",
"name": "To Do",
"self": "https://jira.corp.company.com/rest/api/2/statuscategory/2"
}
},
"subtasks": [
{
"fields": {
"issuetype": {
"avatarId": 10316,
"description": "The sub-task of the issue",
"iconUrl": "https://jira.corp.company.com/secure/viewavatar?size=xsmall&avatarId=10316&avatarType=issuetype",
"id": "10101",
"name": "Sub-task",
"self": "https://jira.corp.company.com/rest/api/2/issuetype/10101",
"subtask": true
},
"priority": {
"iconUrl": "https://jira.corp.company.com/images/icons/priorities/medium.svg",
"id": "3",
"name": "Medium",
"self": "https://jira.corp.company.com/rest/api/2/priority/3"
},
"status": {
"description": "",
"iconUrl": "https://jira.corp.company.com/",
"id": "10000",
"name": "Backlog",
"self": "https://jira.corp.company.com/rest/api/2/status/10000",
"statusCategory": {
"colorName": "blue-gray",
"id": 2,
"key": "new",
"name": "To Do",
"self": "https://jira.corp.company.com/rest/api/2/statuscategory/2"
}
},
"summary": "Disable user account in Local AD"
},
"id": "16916",
"key": "TECH-728",
"self": "https://jira.corp.company.com/rest/api/2/issue/16916"
}
],
"summary": "disable user mm",
"timeestimate": null,
"timeoriginalestimate": null,
"timespent": null,
"updated": "2018-03-06T21:27:22.000+0000",
"versions": [],
"votes": {
"hasVoted": false,
"self": "https://jira.corp.company.com/rest/api/2/issue/TECH-726/votes",
"votes": 0
},
"watches": {
"isWatching": true,
"self": "https://jira.corp.company.com/rest/api/2/issue/TECH-726/watchers",
"watchCount": 1
},
"workratio": -1
},
"id": "16914",
"key": "TECH-726",
"self": "https://jira.corp.company.com/rest/api/2/issue/16914"
}
],
"maxResults": 50,
"startAt": 0,
"total": 1
}
How to extract only part in subtasks section
(subtask:true) ?
tried with:
jq -r '.issues[] | .fields.issuetype.subtask' 1.json # and
jq -r '.subtasks[] |.fields.issuetype.subtask' 1.json
but always get false
jq -r '.subtasks[] | .fields.issuetype.subtask' 1.json
jq: error (at 1.json:231): Cannot iterate over null (null)
jq solution:
jq '.issues[].fields.subtasks[].fields | .issuetype.subtask, .summary' 1.json
The output:
true
"Disable user account in Local AD"
With respect to a best-practice mechanism to iterate over output in bash (assuming, here, that the subtask field will never contain a literal tab, and that summary will never contain a literal newline):
while IFS=$'\t' read -r subtask summary; do
echo "Got subtask $subtask and summary $summary"
done < <(jq -r '.issues[].fields.subtasks[].fields
| [.issuetype.subtask, .summary] | #tsv')
If you want to avoid those assumptions, you can do even better by using NUL delimiters, which will correctly handle all values which can potentially be stored in a variable in bash:
while IFS= read -r -d '' subtask && IFS= read -r -d '' summary; do
printf 'Got subtask %q and summary %q\n' "$subtask" "$summary"
done < <(jq -j '.issues[].fields.subtasks[].fields
| (.issuetype.subtask, "\u0000", .summary, "\u0000")')
Community Wiki since this answer is intended to address an issue observed in comments on the accepted answer, rather than addressing the original question as such.
i have JSON file and want to extract only some values
How to extract only "key": "TECH-456",
and "key": "TECH", (values after key)
{
"expand": "names,schema",
"issues": [
{
"expand": "operations,versionedRepresentations,editmeta,changelog,renderedFields",
"fields": {
"aggregateprogress": {
"percent": 100,
"progress": 86400,
"total": 86400
},
"aggregatetimeestimate": 0,
"aggregatetimeoriginalestimate": 57600,
"aggregatetimespent": 86400,
"assignee": {
"active": true,
"avatarUrls": {
"16x16": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=16",
"24x24": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=24",
"32x32": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=32",
"48x48": "https://secure.gravatar.com/avatar/5d92f3ce51d4a090cdcb9b77ee890989?d=mm&s=48"
},
"displayName": "user1",
"emailAddress": "user1#gmail.com",
"key": "user1",
"name": "user1",
"self": "https://mycompany/rest/api/2/user?username=user1",
"timeZone": "Europe/Belgrade"
},
"components": [],
"created": "2018-01-10T10:23:01.000+0000",
"creator": {
"active": true,
"avatarUrls": {
"16x16": "https://mycompany/secure/useravatar?size=xsmall&avatarId=10349",
"24x24": "https://mycompany/secure/useravatar?size=small&avatarId=10349",
"32x32": "https://mycompany/secure/useravatar?size=medium&avatarId=10349",
"48x48": "https://mycompany/secure/useravatar?avatarId=10349"
},
"displayName": "user2",
"emailAddress": "user2#gmail.com",
"key": "user2",
"name": "user2",
"self": "https://mycompany/rest/api/2/user?username=user2",
"timeZone": "Zulu"
},
"customfield_10000": null,
"customfield_10001": null,
"customfield_10002": null,
"customfield_10004": "0|i00n0f:",
"customfield_10005": null,
"customfield_10006": null,
"customfield_10100": null,
"customfield_10101": [],
"customfield_10102": null,
"customfield_10103": null,
"customfield_10107": {
"id": "10400",
"self": "https://mycompany/rest/api/2/customFieldOption/10400",
"value": "Hentsu Internal"
},
"customfield_10108": null,
"customfield_10200": null,
"customfield_10201": "2018-01-12",
"customfield_10202": "2018-01-12",
"customfield_10203": null,
"customfield_10204": null,
"customfield_10205": null,
"customfield_10206": null,
"customfield_10300": "com.atlassian.servicedesk.plugins.approvals.internal.customfield.ApprovalsCFValue#40efdb56",
"customfield_10301": null,
"customfield_10302": null,
"customfield_10600": null,
"customfield_10700": null,
"customfield_11000": null,
"customfield_11001": null,
"customfield_11002": null,
"customfield_11003": null,
"customfield_11004": null,
"customfield_11005": null,
"customfield_11006": null,
"customfield_11007": null,
"customfield_11008": null,
"customfield_11009": null,
"customfield_11010": null,
"customfield_11011": null,
"customfield_11012": null,
"customfield_11013": null,
"customfield_11014": null,
"customfield_11015": null,
"customfield_11016": null,
"customfield_11017": null,
"customfield_11018": null,
"customfield_11019": null,
"customfield_11100": null,
"customfield_11101": null,
"customfield_11102": null,
"description": ".",
"duedate": null,
"environment": null,
"fixVersions": [],
"issuelinks": [],
"issuetype": {
"avatarId": 10318,
"description": "A task that needs to be done.",
"iconUrl": "https://mycompany/secure/viewavatar?size=xsmall&avatarId=10318&avatarType=issuetype",
"id": "10100",
"name": "Task",
"self": "https://mycompany/rest/api/2/issuetype/10100",
"subtask": false
},
"labels": [],
"lastViewed": "2018-02-22T15:47:47.792+0000",
"priority": {
"iconUrl": "https://mycompany/images/icons/priorities/medium.svg",
"id": "3",
"name": "Medium",
"self": "https://mycompany/rest/api/2/priority/3"
},
"progress": {
"percent": 100,
"progress": 86400,
"total": 86400
},
"project": {
"avatarUrls": {
"16x16": "https://mycompany/secure/projectavatar?size=xsmall&pid=10001&avatarId=10201",
"24x24": "https://mycompany/secure/projectavatar?size=small&pid=10001&avatarId=10201",
"32x32": "https://mycompany/secure/projectavatar?size=medium&pid=10001&avatarId=10201",
"48x48": "https://mycompany/secure/projectavatar?pid=10001&avatarId=10201"
},
"id": "10001",
"key": "TECH",
"name": "Technology",
"self": "https://mycompany/rest/api/2/project/10001"
},
"reporter": {
"active": true,
"avatarUrls": {
"16x16": "https://mycompany/secure/useravatar?size=xsmall&avatarId=10349",
"24x24": "https://mycompany/secure/useravatar?size=small&avatarId=10349",
"32x32": "https://mycompany/secure/useravatar?size=medium&avatarId=10349",
"48x48": "https://mycompany/secure/useravatar?avatarId=10349"
},
"displayName": "user2",
"emailAddress": "user2#gmail.com",
"key": "user2",
"name": "user2",
"self": "https://mycompany/rest/api/2/user?username=user2",
"timeZone": "Zulu"
},
"resolution": null,
"resolutiondate": null,
"status": {
"description": "",
"iconUrl": "https://mycompany/images/icons/statuses/inprogress.png",
"id": "3",
"name": "In-Progress",
"self": "https://mycompany/rest/api/2/status/3",
"statusCategory": {
"colorName": "yellow",
"id": 4,
"key": "indeterminate",
"name": "In Progress",
"self": "https://mycompany/rest/api/2/statuscategory/4"
}
},
"subtasks": [],
"summary": "Build the Fortimanage Portal",
"timeestimate": 0,
"timeoriginalestimate": 57600,
"timespent": 86400,
"updated": "2018-01-31T15:22:06.000+0000",
"versions": [],
"votes": {
"hasVoted": false,
"self": "https://mycompany/rest/api/2/issue/TECH-456/votes",
"votes": 0
},
"watches": {
"isWatching": false,
"self": "https://mycompany/rest/api/2/issue/TECH-456/watchers",
"watchCount": 1
},
"workratio": 150
},
"id": "15377",
"key": "TECH-456",
"self": "https://mycompany/rest/api/2/issue/15377"
}
],
"maxResults": 50,
"startAt": 0,
"total": 1
}
The right way with jq tool:
jq -r '.issues[0] | .key, .fields.project.key' file.json
The output:
TECH-456
TECH
Below details is my shipment details. I want to loop through this JSON and get each checkpoint details.
How can I do this with Ruby
This is my controller:
#asd = AfterShip::V4::Tracking.get('ups', '1Z31Y1Y90490064644')
this is my view page where i get json data
= #asd.to_json`
This is the JSON:
{
"meta": {
"code": 200
},
"data": {
"tracking": {
"id": "560b87b38c9079f272e98dfc",
"created_at": "2015-09-30T06:56:51+00:00",
"updated_at": "2015-09-30T06:56:55+00:00",
"last_updated_at": "2015-09-30T06:56:55+00:00",
"tracking_number": "1Z31Y1Y90490064644",
"slug": "ups",
"active": false,
"android": [
],
"custom_fields": null,
"customer_name": null,
"delivery_time": 7,
"destination_country_iso3": "GBR",
"emails": [
"pu#l.com"
],
"expected_delivery": null,
"ios": [
],
"note": null,
"order_id": null,
"order_id_path": null,
"origin_country_iso3": "HKG",
"shipment_package_count": 1,
"shipment_pickup_date": "2015-08-24T16:00:00",
"shipment_delivery_date": "2015-09-01T14:22:00",
"shipment_type": "UPS SAVER",
"shipment_weight": 0.5,
"shipment_weight_unit": "kg",
"signed_by": "MANTON (RESIDENTIAL)",
"smses": [
],
"source": "api",
"tag": "Delivered",
"title": "1Z31Y1Y90490064644",
"tracked_count": 1,
"unique_token": "bkGcaTOJDe",
"checkpoints": [
{
"slug": "ups",
"city": null,
"created_at": "2015-09-30T06:56:55+00:00",
"location": "HK",
"country_name": "HK",
"message": "BILLING INFORMATION RECEIVED",
"country_iso3": "HKG",
"tag": "InfoReceived",
"checkpoint_time": "2015-08-25T23:05:47",
"coordinates": [
],
"state": null,
"zip": null
},
{
"slug": "ups",
"city": null,
"created_at": "2015-09-30T06:56:55+00:00",
"location": null,
"country_name": null,
"message": "YOUR PACKAGE WAS RELEASED BY THE CLEARING AGENCY.",
"country_iso3": null,
"tag": "InTransit",
"checkpoint_time": "2015-08-27T16:57:00",
"coordinates": [
],
"state": null,
"zip": null
},
{
"slug": "ups",
"city": null,
"created_at": "2015-09-30T06:56:55+00:00",
"location": null,
"country_name": null,
"message": "YOUR PACKAGE WAS RELEASED BY THE CLEARING AGENCY.",
"country_iso3": null,
"tag": "InTransit",
"checkpoint_time": "2015-08-27T17:07:00",
"coordinates": [
],
"state": null,
"zip": null
}
}
}
}
What you are getting here is an instance of Hash class (the response JSON is already parsed).
tracking = AfterShip::V4::Tracking.get('ups', '1Z31Y1Y90490064644')
tracking['data']['tracking']['id']
# => "560b87b38c9079f272e98dfc"