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

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.

Replies are listed 'Best First'.
Re^6: Converting hash into js object properties
by nysus (Parson) on Nov 21, 2017 at 16:40 UTC

    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.

        OK, so adding double quotes to the jQuery directly didn't break anything, the validator script still works with them. So I guess I'm good to go. Thanks!

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

        Ok, this is for the jquery validation module and is being used inside of a jquery call like so:

        $("#myform").validate({ rules: { contact: { required: true, email: { depends: function(element) { return $("#contactform_email").is(":checked"); } } } } });

        So, I'm not familiar enough with jQuery to know if adding the double quotes will break things or not. I guess I could try and see what happens.

        $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.

      What led you to that conclusion?