Hello All,

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

{ "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" }
My code
#!/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

{"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
Is there a better way to do it ? or am I missing something? Thank you

In reply to converting JSON to CSV by cbtshare

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.