in reply to Re^3: Converting hash into js object properties
in thread Converting hash into js object properties

Hmm, Data::Dumper gets me very close:
use Data::Dumper; $Data::Dumper::Pair = ' : '; $Data::Dumper::Quotekeys = 0;

The keys are not quoted using this method. Only problem now is that the true values are printed as literals with 'true'.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re^5: Converting hash into js object properties
by haukex (Archbishop) on Nov 21, 2017 at 16:35 UTC

    Data::Dumper is a debugging tool, not necessarily appropriate for serialization, especially not for JSON.

    See the documentation of JSON::MaybeXS: JSON->true and JSON->false will give you boolean values.

      Yeah, saw that, but I still have the issue where the keys are getting double quoted with JSON::MaybeXS. I don't think I'm looking for purse JSON output. The outputted keys need to be barewords, I believe.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        The outputted keys need to be barewords, I believe.

        Ah, I see, I misread your post here and I thought you were talking about the extra quotes in the values, not the keys. Yes, the quotes around the keys are required by JSON, but JSON is a subset of JavaScript, so if someone is requiring you to omit the quotes, I'd ask why that is and why they can't accept regular JSON.

        The outputted keys need to be barewords, I believe.

        What led you to that conclusion?