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

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

  • Comment on Re^6: Converting hash into js object properties

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

        adding double quotes to the jQuery directly didn't break anything

        jQuery is "just" a library, in that way it is similar to, for example, Moo: it just makes good/clever use of existing language syntax to provide an interface that makes it look like it's adding new syntax to the language (e.g. jQuery's $(...), Moo's has), but it is in fact working within the confines of the language (other modules can be added to provide sugar). The same way one can write regular Perl subs into Moo classes and use everything that Perl has to offer, one can use all of vanilla JavaScript when working with jQuery.

      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

Re^7: Converting hash into js object properties
by Your Mother (Archbishop) on Nov 21, 2017 at 16:48 UTC
    The outputted keys need to be barewords, I believe.

    What led you to that conclusion?