A json file in my repository has object arrays. In Azure pipeline I want to read the file and replace certain object values before proceeding with other tasks like publishing, etc. Example json file :
"Routes": [
{
"UpstreamPathTemplate": "/product",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7133
}
]
},
{
"UpstreamPathTemplate": "/product/delete",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7133
}
]
},
{
"UpstreamPathTemplate": "/order",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 7203
}
]
}
]
Now I want to pick the first unique word after '/' from UpstreamPathTemplate for each object and replace DownstreamHostAndPorts[0].Host with that word. Also all Port value should be 80. So after replacement above Json would look like
"Routes": [
{
"UpstreamPathTemplate": "/product",
"DownstreamHostAndPorts": [
{
"Host": "product",
"Port": 80
}
]
},
{
"UpstreamPathTemplate": "/product/delete",
"DownstreamHostAndPorts": [
{
"Host": "product",
"Port": 80
}
]
},
{
"UpstreamPathTemplate": "/order",
"DownstreamHostAndPorts": [
{
"Host": "order",
"Port": 80
}
]
}
]