powershell - Powershell - 从 JSON 数组返回特定行的值
问题描述
很抱歉不得不在这里问这样的问题,自学的 powershell 用户。有一个问题,我似乎无法从 GET Invoke-RestMethod 的 JSON 返回中获得我想要的值。
我正在尝试提取 JIRA 票证数据,以便检查自定义字段是否已使用值更新。我尝试直接在响应中调用自定义字段,但是由于响应的格式设置它只会返回数据列,因此我无法在我的代码中使用此响应。
我的代码如下:
$response = Invoke-RestMethod "https://jira-ceg.atlassian.net/rest/servicedeskapi/request/$JIRATICKET" -Method 'GET' -Headers $headers
$tester = $response.requestFieldValues
$tester
我从 JIRA 得到的回复如下:
fieldId label value
------- ----- -----
summary Summary STAFF-NEW - XXXX- NAME
customfield_10108 iTrent Information Employee ID: XXXX...
customfield_10086 Checklist Text --- ERROR - No Role Entitlement Found - Contact Service Admin
description Description A new employee has joined. Please process with the data above.
customfield_10191 New AD Address XXXX@XXXXX.com
我想捕获字段 customfield_10191 的值,该字段有时也可能是空白的,稍后我将在脚本中对其进行测试。知道我该怎么做吗?
提前致谢!
解决方案
如果$tester
是具有属性fieldId
、label
和的对象value
,则可以使用成员访问(语法object.property
)和Where-Object的组合:
($tester | Where fieldId -eq 'customfield_10191').value
选择对象也适用:
$tester | Where fieldId -eq 'customfield_10191' | Select-Object -Expand value
要返回包含特定客户的对象:
$tester | Where fieldId -eq 'customfield_10191'
推荐阅读
- mysql - 如何查询一个表的同一列中的两个不同对象,这些对象与另一个表中的不同列相关?
- azure - SecretClient - 从 azure KeyVault 获取秘密
- javascript - file:/// 和 file://///%3F/ 的区别
- python - 如何在 python 中的 Dataframe 中创建新的自动增量列
- python - PySimpleGui 显示来自数据库的数据
- css - 使用 V-for 渲染 Vuejs 中的项目列表后 CSS 页脚不粘在底部
- automation - CircleCI 中等效的 GitHub Actions 策略矩阵
- python - 反转熊猫数据框并连接结果
- dax - 不使用 CALCULATE 的不同计数
- javascript - React 中数据属性的通用解决方案