mardi 23 août 2022

Ruby print JSON value - no implicit conversion of String into Integer

I'm trying to print only the value of a JSON and I'm getting the error no implicit conversion of String into Integer.

Any idea how I can resolve this?

puts test.class

Azure::Armrest::ArmrestCollection

Here is the output of the varaible and I want to print only the quantity value.

puts test

[----] I, [2022-08-23T08:59:20.279357 #550:bc494]  INFO -- automation: Method STDOUT: {"id":"/subscriptions/123456/providers/Microsoft.Commerce/UsageAggregates/Daily_BRSDT_20220801_0000","name":"Daily_BRSDT_20220801_0000","type":"Microsoft.Commerce/UsageAggregate","properties":{"subscriptionId":"123456","usageStartTime":"2022-07-31T00:00:00+00:00","usageEndTime":"2022-08-01T00:00:00+00:00","meterName":"Data Transfer Out","meterRegion":"North America","meterCategory":"Bandwidth","meterSubCategory":"Inter-Region","unit":"1 GB","instanceData":"{\"Microsoft.Resources\":{\"resourceUri\":\"/subscriptions/123456/resourceGroups/cloud-shell-storage-centralindia/providers/Microsoft.Compute/virtualMachines/ubuntu975\",\"location\":\"eastus\",\"additionalInfo\":{\"PipelineType\":\"v2\",\"DataTransferDirection\":\"DataTrOut\"}}}","meterId":"dbefcfc1-e3f6-409b-be6d-9cd7b00724a5","infoFields":{},"quantity":9.052455425262451e-07}}
[----] I, [2022-08-23T08:59:20.280435 #550:bc494]  INFO -- automation: Method STDOUT: {"id":"/subscriptions/123456/providers/Microsoft.Commerce/UsageAggregates/Daily_BRSDT_20220801_0000","name":"Daily_BRSDT_20220801_0000","type":"Microsoft.Commerce/UsageAggregate","properties":{"subscriptionId":"123456","usageStartTime":"2022-07-31T00:00:00+00:00","usageEndTime":"2022-08-01T00:00:00+00:00","meterName":"Dynamic Public IP","meterCategory":"Virtual Network","meterSubCategory":"IP Addresses","unit":"1 Hour","instanceData":"{\"Microsoft.Resources\":{\"resourceUri\":\"/subscriptions/123456/resourceGroups/cloud-shell-storage-centralindia/providers/Microsoft.Network/publicIPAddresses/Ubuntu975-publicIp\",\"location\":\"eastus\",\"additionalInfo\":{\"IpAddress\":\"20.25.57.9\",\"PlatformType\":\"V2-Agg\"}}}","meterId":"f114cb19-ea64-40b5-bcd7-aee474b62853","infoFields":{},"quantity":1.0}}

puts test["properties"]["quantity"]

[----] E, [2022-08-23T08:59:28.949873 #544:b6620] ERROR -- automation: <AEMethod getcostusage> [no implicit conversion of String into Integer]
/CloudForms_Essentials/Integration/Azure/StateMachines/getCostUsage:79:in `[]'
/CloudForms_Essentials/Integration/Azure/StateMachines/getCostUsage:79:in `<main>'
[----] I, [2022-08-23T08:59:28.974301 #544:ac260]  INFO -- automation: <AEMethod [/CloudForms_Essentials/Integration/Azure/StateMachines/getCostUsage]> Ending

If I try JSON.parse(test) then I get this error.

[----] E, [2022-08-23T09:18:39.022825 #553:bcaac] ERROR -- automation: <AEMethod getcostusage> [no implicit conversion of Azure::Armrest::ArmrestCollection into String]

Aucun commentaire:

Enregistrer un commentaire