I want to take all the key-value pairs after the \"tags\" under "instanceData" and make them key-value pairs under "properties".
I have this...
{
"id": "/subscriptions/1234abcd-ab12-12ab-12ab-abcdfghi1234/Daily_BRSDT_20161214_0000",
"name": "Daily_BRSDT_20161214_0000",
"type": "Microsoft.Commerce/UsageAggregate",
"properties": {
"subscriptionId": "1234abcd-ab12-12ab-12ab-abcdfghi1234",
"usageStartTime": "2017-03-08T00:00:00+00:00",
"usageEndTime": "2017-03-09T00:00:00+00:00",
"meterName": "Standard IO - File Read Operation Units (in 10,000s)",
"meterCategory": "Data Management",
"unit": "10,000s",
"instanceData": "{\"Microsoft.Resources\":{\"resourceUri\":\"/subscriptions/1234abcd-ab12-12ab-12ab-abcdfghi1234/resourceGroups/default-resource-group67/providers/Microsoft.Storage/storageAccounts/defaultstorage67\",\"location\":\"ussouthcentral\",\"tags\":{\"ProjectName\":\"default Portal\",\"billTo\":\"Technology\",\"component\":\"Persistant Storage\",\"department\":\"Technology\",\"displayName\":\"default Portal Storage Account\",\"enviornment\":\"default\",\"function\":\"Reporting\",\"matterNumber\":\"999999\",\"primaryowner\":\"[email protected]\",\"productLine\":\"Information Components\",\"secondaryowner\":\"[email protected]\",\"version\":\"1.0.0.0\"}}}",
"meterId": "12345ab-259d-4206-a6ae-12345678abcd",
"infoFields": {},
"quantity": 0.0004
}
}
I want this...
{
"id": "/subscriptions/1234abcd-ab12-12ab-12ab-abcdfghi1234/Daily_BRSDT_20161214_0000",
"name": "Daily_BRSDT_20161214_0000",
"type": "Microsoft.Commerce/UsageAggregate",
"properties": {
"subscriptionId": "1234abcd-ab12-12ab-12ab-abcdfghi1234",
"usageStartTime": "2017-03-08T00:00:00+00:00",
"usageEndTime": "2017-03-09T00:00:00+00:00",
"meterName": "Standard IO - File Read Operation Units (in 10,000s)",
"meterCategory": "Data Management",
"unit": "10,000s",
"instanceData": "{\"Microsoft.Resources\":{\"resourceUri\":\"/subscriptions/1234abcd-ab12-12ab-12ab-abcdfghi1234/resourceGroups/default-resource-group67/providers/Microsoft.Storage/storageAccounts/defaultstorage67\",\"location\":\"ussouthcentral\"}}",
"ProjectName":"default Portal",
"billTo":"Technology",
"component":"Persistant Storage",
"department":"Technology",
"displayName":"default Portal Storage Account",
"enviornment":"default",
"function":"Reporting",
"matterNumber":"999999",
"primaryowner":"[email protected]",
"productLine":"Information Components",
"secondaryowner":"[email protected]",
"version":"1.0.0.0",
"meterId": "12345ab-259d-4206-a6ae-12345678abcd",
"infoFields": {},
"quantity": 0.0004
}
}
Is there a simple way to convert this? I am attempting to do this with RegEx with no luck.
I would recommend looking at something like this:
How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?
Serialize List<KeyValuePair<string, string>> as JSON
Effectively you're going to need to strip out the one key you want to be parsed, and re-add that to your JSON object.
Json.NET - Newtonsoft's tool is great for working with JSON. http://www.newtonsoft.com/json
Easiest way to do it:
List<KeyValuePair<string,string>>.
This is an easy way to do it, though not the most efficient way.