Hello monks,
I want to convert a perl data structure into JSON.
For that, I need to convert an epoch datetime of milliseconds to JSON type. Following is the initial code.
Problem is that I want a single backslash with the boundaries of word "Date", but each time it gets converted to 2 backslashes.
Couldn't find any direct way to convert a date into JSON as we do with JSON::PP::true or other things. Quite confused with this.
my $roundParams = { 'AllowParticipantsToSeeEachOther' => JSON::PP:: +true, 'DurationInMinutes' => 10, 'MaxGamePegValue' => 5, 'MaxNumberOfCrackAttemptsPerCode' => 18, 'MaxNumberOfCrackAttemptsPerTeam' => 0, 'NumberOfDefaultHostParticipants' => 1, 'NumberOfPegsInRound' => 4, 'RoundStartTime' => "\\/Date(" + . $milliSeconds . ")\\/", 'TimeBetweenRoundATimeBetweenRoundAttemptsInSeconds' => 10 }; say Dumper $roundParams; say $roundParams->{'RoundStartTime'}; say to_json $roundParams;

Output:

{"AllowParticipantsToSeeEachOther":true,"TimeBetweenRoundATimeBetweenR +oundAttemptsInSeconds":10,"NumberOfDefaultHostParticipants":1,"MaxNum +berOfCrackAttemptsPerTeam":0,"RoundStartTime":"\\/Date(1401265928689) +\\/","NumberOfPegsInRound":4,"DurationInMinutes":10,"MaxNumberOfCrack +AttemptsPerCode":18,"MaxGamePegValue":5}
Tried various things like eliminating one backslash for escape character, adding \e, using qq etc., but nothing worked out. Would be thankful if you could guide in that.

In reply to Json epoch datetime with perl by gurpreetsingh13

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.