cbtshare has asked for the wisdom of the Perl Monks concerning the following question:
I am try to convert aws metrics gotten from the awscli , and turn that into a more human readable format so users can better understand the data but I am not having much success, can you please assist.
my sample data
My code{ "Datapoints": [ { "Timestamp": "2017-03-01T04:05:00Z", "Average": 145.80000000000001, "Unit": "Count" }, { "Timestamp": "2017-03-01T10:35:00Z", "Average": 182.19999999999999, "Unit": "Count" }, { "Timestamp": "2017-03-01T05:30:00Z", "Average": 180.19999999999999, "Unit": "Count" }, { "Timestamp": "2017-03-01T17:35:00Z", "Average": 140.40000000000001, "Unit": "Count" }, { "Timestamp": "2017-03-01T01:05:00Z", "Average": 102.2, "Unit": "Count" }, { "Timestamp": "2017-03-01T22:15:00Z", "Average": 114.2, "Unit": "Count" }, { "Timestamp": "2017-03-01T05:45:00Z", "Average": 131.19999999999999, "Unit": "Count" }, { "Timestamp": "2017-03-01T10:10:00Z", "Average": 201.40000000000001, "Unit": "Count" }, { "Timestamp": "2017-03-01T09:00:00Z", "Average": 106.40000000000001, "Unit": "Count" }, { "Timestamp": "2017-03-01T04:35:00Z", "Average": 159.59999999999999, "Unit": "Count" } ], "Label": "DatabaseConnections" }
#!/usr/bin/perl use strict; use warnings; use JSON::PP; use CGI; my $json = JSON::PP->new->utf8; #my $json_text = CGI->new->param('aws.json'); #my $perl_scalar = $json->decode( $json_text ); local $/; open( my $fh, '<', 'aws.json' ); my $json_text = <$fh>; my $perl_scalar = decode_json($json_text); #print encode_json($perl_scalar); print $json->utf8->encode($perl_scalar);
My results
Is there a better way to do it ? or am I missing something? Thank you{"Datapoints":[{"Average":145.8,"Timestamp":"2017-03-01T04:05:00Z","Un +it":"Count"},{"Av erage":182.2,"Timestamp":"2017-03-01T10:35:00Z","Unit":"Count"},{"Aver +age":108,"Timesta mp":"2017-03-01T18:50:00Z","Unit":"Count"},{"Average":134.8,"Timestamp +":"2017-03-01T01: 45:00Z","Unit":"Count"},{"Average":99.4,"Timestamp":"2017-03-01T23:30: +00Z","Unit":"Coun t"},{"Average":234,"Timestamp":"2017-03-01T15:15:00Z","Unit":"Count"}, +{"Average":164.6, "Timestamp":"2017-03-01T06:25:00Z","Unit":"Count"},{"Average":156.4,"T +imestamp":"2017-0 3-01T12:55:00Z","Unit":"Count"},{"Average":111.2,"Timestamp":"2017-03- +01T21:10:00Z","Un it":"Count"},{"Average":156.8,"Timestamp":"2017-03-01T20:40:00Z","Unit +":"Count"},{"Aver age":163.2,"Timestamp":"2017-03-01T03:35:00Z","Unit":"Count"},{"Averag +e":153.8,"Timesta mp":"2017-03-01T11:50:00Z","Unit":"Count"},{"Average":155.8,"Timestamp +":"2017-03-01T18: 20:00Z","Unit":"Count"},{"Average":109.8,"Timestamp":"2017-03-01T16:30 +:00Z","Unit":"Cou nt"},{"Average":159.2,"Timestamp":"2017-03-01T08:15:00Z","Unit":"Count +"},{"Average":145 .8,"Timestamp":"2017-03-01T23:00:00Z","Unit":"Count"} ...and more of the same till the end
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: converting JSON to CSV
by Anonymous Monk on Apr 06, 2017 at 22:42 UTC | |
by cbtshare (Monk) on Apr 07, 2017 at 01:50 UTC | |
by AnomalousMonk (Archbishop) on Apr 07, 2017 at 03:25 UTC | |
by shmem (Chancellor) on Apr 07, 2017 at 21:11 UTC | |
by haukex (Archbishop) on Apr 08, 2017 at 09:14 UTC | |
by cbtshare (Monk) on Apr 07, 2017 at 00:10 UTC |