I need PreTaxCost and ResourceGroup out of this json, for further operations.
{
"id": "subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.CostManagement/Query/00000000-0000-0000-0000-000000000000",
"name": "55312978-ba1b-415c-9304-cfd9c43c0481",
"type": "microsoft.costmanagement/Query",
"properties": {
"nextLink": null,
"columns": [
{
"name": "PreTaxCost",
"type": "Number"
},
{
"name": "ResourceGroup",
"type": "String"
},
{
"name": "Currency",
"type": "String"
}
],
"rows": [
[
0.009865586851323632,
"Ict_StratAndPlan_GoldSprova_Prod_0",
"USD"
],
[
218.68795741935486,
"Ict_StratAndPlan_GoldSprova_Prod_1",
"USD"
],
[
2.10333307059661,
"ScreenSharingTest-peer1",
"USD"
],
[
0.14384913581657052,
"Ssbciotelement01",
"USD"
]
]
}
}
2
Answers
Welcome to StackOverflow! Usually, the best way of parsing a json document, is to create an object structure that you can deserialize it to. I usually use a tool like https://json2csharp.com/. Make sure to check "Use Pascal Case" and "Use JsonPropertyName (.NET Core)". The generate class should look something like this:
From there you can deserialize the json using:
Then getting the properties is easy with some C# code.
You can use this set of class to give type to your json.
After keeping these class in your code.
The Code above will filter out the data you needed from the json string.I am Assuming the position of the data for column is accurate as it is in json string you provided.