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

my %hash = ( rules => {name => '"required"', ...

Just tried that but the property keys get surrounded by quotes in the JSON output.

The module is just faithfully converting your Perl data structure into a JSON one. Your Perl strings contain the double quotes, so the JSON ones do too. If you don't want that, strip the double quotes from the Perl strings before converting to JSON (or don't add them in the first place).

Update: Sorry, I thought you were talking about the extra quotes in the values, but you meant the keys. See replies below.

Replies are listed 'Best First'.
Re^4: Converting hash into js object properties
by nysus (Parson) on Nov 21, 2017 at 16:26 UTC
    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

      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