需要从 json 输出的特定字段值中删除“:”

Need to remove ':' from the specific field value from json output

我正在尝试从 json 输出的特定字段值中删除 :。

请找到 json 输出:

{
    "suite_id": 111,
    "object_type": 2,
    "jobs": [
        {
            "jobId": 222,
            "creationTime": "2022-04-12T13:38:02Z",
            "browser": "chrome",
            "browserVersion": "",
            "platform": "win",
            "platform_version": "",
            "appiumVersion": "",
            "deviceName": "",
            "deviceOrientation": "",
            "isSerial": false,
            "totalExecutions": 1,
            "isRetryExecAvailable": false,
            "jobExecutionStatus": 1,
            "etrs": {
                "tasks": [
                    {
                        "executionId": 333,
                        "executionName": "Testing",
                        "executionStatus": "SUCCESS",
                        "restartExecutionStatus": "",
                        "restartExecutionId": 0,
                        "restartExecutionReportUrl": "",
                        "restartExecutionVideoUrl": "",
                        "initiatedOn": "2022-04-12T13:38:05Z",
                        "projectName": "Testproject",
                        "projectId": 1,
                        "executionVideoUrl": "",
                        "reportUrl": "avsfershd",
                        "testcaseId": 666,
                        "testCaseName": "testcase",
                        "errorsCount": 0,
                        "warningsCount": 0,
                        "statusMessage": "Success"
                    }
                ],
                "total_execs": 0
            },
            "environmentType": "local"
        }
]
}

我正在从 json 的输出中获取 initiatedOn 值 $值 = $Output.jobs.etrs.tasks.initiatedOn

这给我值 2022-04-12T13:38:05Z 但我需要从值中删除 :。

谢谢, 希瓦姆

继续我的评论,

我会将此 universal sortable 日期格式的字符串转换为 [datetime] 对象,您可以根据需要对其进行格式化,而不是切断字符串的一部分..

$value = '{0:yyyy-MM-dd}' -f [datetime]$Output.jobs.etrs.tasks.initiatedOn

您的示例以祖鲁时间 (UTC + 00:00) 的 Z 结尾,但另一个值可能看起来像 2022-04-12T13:38:05+08:00,因此最好将其转换为日期时间。