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

Time:04-20

I am trying to remove the : from the specific field value from the json output.

Please find the json output:

{
    "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"
        }
]
}

I am taking the initiatedOn value from the json output by $value = $Output.jobs.etrs.tasks.initiatedOn

which giving me value 2022-04-12T13:38:05Z but I need to remove : from the value.

Thank you, Shivam

CodePudding user response:

Continuing from my comment,

I would cast this universal sortable date formatted string into a [datetime] object, which you can format as you like instead of cutting off part of the string..

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

Your example ends with the Z for Zulu Time (UTC 00:00), but another value may look like 2022-04-12T13:38:05 08:00, so converting it to datetime would IMO be best.

  • Related