{"id":16310086,"url":"https://github.com/grinnz/mojo-json-maybexs","last_synced_at":"2025-04-13T17:12:01.000Z","repository":{"id":23762202,"uuid":"27136762","full_name":"Grinnz/Mojo-JSON-MaybeXS","owner":"Grinnz","description":"Module to use JSON::MaybeXS as the JSON renderer for Mojolicious.","archived":false,"fork":false,"pushed_at":"2019-08-07T17:01:45.000Z","size":93,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-16T08:14:13.250Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://metacpan.org/pod/Mojo::JSON::MaybeXS","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Grinnz.png","metadata":{"files":{"readme":"README.pod","changelog":"Changes","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-25T17:09:21.000Z","updated_at":"2019-08-07T17:01:45.000Z","dependencies_parsed_at":"2022-08-22T05:50:45.722Z","dependency_job_id":null,"html_url":"https://github.com/Grinnz/Mojo-JSON-MaybeXS","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Grinnz%2FMojo-JSON-MaybeXS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Grinnz%2FMojo-JSON-MaybeXS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Grinnz%2FMojo-JSON-MaybeXS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Grinnz%2FMojo-JSON-MaybeXS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Grinnz","download_url":"https://codeload.github.com/Grinnz/Mojo-JSON-MaybeXS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248750109,"owners_count":21155687,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T21:23:40.185Z","updated_at":"2025-04-13T17:12:00.982Z","avatar_url":"https://github.com/Grinnz.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"=pod\n\n=head1 NAME\n\nMojo::JSON::MaybeXS - use JSON::MaybeXS as the JSON encoder for Mojolicious\n\n=head1 SYNOPSIS\n\n use Mojo::JSON::MaybeXS;\n use Mojo::JSON qw/encode_json decode_json true false/;\n \n # Preload for scripts using Mojo::JSON\n $ perl -MMojo::JSON::MaybeXS -S morbo myapp.pl\n \n # Must be set in environment for hypnotoad\n $ PERL5OPT=-MMojo::JSON::MaybeXS hypnotoad myapp.pl\n\n=head1 DESCRIPTION\n\nL\u003cMojo::JSON::MaybeXS\u003e is a monkey-patch module for using L\u003cJSON::MaybeXS\u003e as\nthe JSON encoder for a L\u003cMojolicious\u003e application, or anything else using\nL\u003cMojo::JSON\u003e. It must be loaded before L\u003cMojo::JSON\u003e so the new functions will\nbe properly exported.\n\nSince L\u003cMojolicious\u003e version 7.87, L\u003cMojo::JSON\u003e has delegated to\nL\u003cCpanel::JSON::XS\u003e by default if installed and recent enough. Installing\nL\u003cMojolicious\u003e version 7.87+ and L\u003cCpanel::JSON::XS\u003e version 4.09+ resolves the\nbelow listed caveats between these modules, and is sufficient to improve the\nperformance of L\u003cMojo::JSON\u003e without the use of this module.\n\n=head1 CAVEATS\n\nL\u003cJSON::MaybeXS\u003e may load different modules behind the scenes depending on what\nis available, and these modules have slightly different behavior from\nL\u003cMojo::JSON\u003e and occasionally from each other. References to the behavior of\nL\u003cJSON::MaybeXS\u003e below are actually describing the behavior shared among the\nmodules it loads.\n\nL\u003cJSON::MaybeXS\u003e is used with the options C\u003ccanonical\u003e, C\u003callow_nonref\u003e,\nC\u003callow_unknown\u003e, C\u003callow_blessed\u003e, and C\u003cconvert_blessed\u003e. C\u003ccanonical\u003e\nenables sorting of hash keys when encoding to JSON objects as L\u003cMojo::JSON\u003e\ndoes. C\u003callow_nonref\u003e allows encoding and decoding of bare values outside of\nhash/array references, since L\u003cMojo::JSON\u003e does not prevent this, in accordance\nwith L\u003cRFC 7159|http://tools.ietf.org/html/rfc7159\u003e. The other options prevent\nthe encoder from blowing up when encountering values that cannot be represented\nin JSON to better match the behavior of L\u003cMojo::JSON\u003e. See below for more\nspecifics.\n\nTo better match the behavior of L\u003cMojo::JSON\u003e, certain options may be enabled\ndepending on the backend that is used. If L\u003cCpanel::JSON::XS\u003e version 3.0112 or\ngreater is loaded, it will be used with the option C\u003cstringify_infnan\u003e. If\neither L\u003cCpanel::JSON::XS\u003e of at least version 3.0206 or L\u003cJSON::PP\u003e is loaded,\nit will be used with the option C\u003cescape_slash\u003e. If L\u003cCpanel::JSON::XS\u003e version\n4.09 or greater is loaded, it will be used with the option C\u003callow_dupkeys\u003e.\n\nAs of this writing, the author has found the following incompatibilities:\n\n=head2 Object Conversion\n\nBoth L\u003cJSON::MaybeXS\u003e and L\u003cMojo::JSON\u003e will attempt to call the TO_JSON method\nof a blessed reference to produce a JSON-friendly structure. If that method\ndoes not exist, L\u003cMojo::JSON\u003e or L\u003cCpanel::JSON::XS\u003e version 3.0207 or greater\nwill stringify the object, while L\u003cJSON::XS\u003e or L\u003cJSON::PP\u003e will always encode\nit to C\u003cnull\u003e.\n\n print encode_json([DateTime-\u003enow]);\n # Mojo::JSON or Cpanel::JSON::XS \u003e= 3.0207: [\"2014-11-30T04:31:13\"]\n # JSON::XS or JSON::PP: [null]\n\n=head2 Unblessed References\n\nL\u003cJSON::MaybeXS\u003e does not allow unblessed references other than to hashes,\narrays, or the scalar values C\u003c0\u003e and C\u003c1\u003e, and will encode them to C\u003cnull\u003e.\nBefore L\u003cMojolicious\u003e version 7.87, L\u003cMojo::JSON\u003e will treat all scalar\nreferences the same as references to C\u003c0\u003e or C\u003c1\u003e and will encode them to\nC\u003ctrue\u003e or C\u003cfalse\u003e depending on their boolean value, and other references\n(code, filehandle, etc) will be stringified.\n\nSince L\u003cMojolicious\u003e version 7.87, L\u003cMojo::JSON\u003e's behavior with unblessed\nreferences is the same as L\u003cJSON::MaybeXS\u003e.\n\n print encode_json([\\'asdf', sub { 1 }]);\n # Mojo::JSON (Mojolicious \u003e= 7.87): [null,null]\n # JSON::MaybeXS: [null,null]\n\n=head2 Escapes\n\nL\u003cMojo::JSON\u003e currently escapes the slash character C\u003c/\u003e for security reasons.\nBefore L\u003cMojolicious\u003e version 7.87, it also escaped the unicode characters\nC\u003cu2028\u003e and C\u003cu2029\u003e. L\u003cCpanel::JSON::XS\u003e version 3.0206 or greater and\nL\u003cJSON::PP\u003e will have the option set to escape the slash character, and\nL\u003cJSON::XS\u003e does not escape these characters. This does not affect decoding of\nthe resulting JSON.\n\n print encode_json([\"/\\x{2028}/\\x{2029}\"]);\n # Mojo::JSON (Mojolicious \u003e= 7.87): [\"\\/ \\/ \"]\n # Cpanel::JSON::XS \u003e= 3.0206 or JSON::PP: [\"\\/ \\/ \"]\n # JSON::XS: [\"/ / \"]\n # Both decode to arrayref containing: \"/\\x{2028}/\\x{2029}\"\n\n=head2 inf and nan\n\nL\u003cMojo::JSON\u003e encodes C\u003cinf\u003e and C\u003cnan\u003e to strings. L\u003cCpanel::JSON::XS\u003e version\n3.0112 or greater will also stringify C\u003cinf\u003e and C\u003cnan\u003e. However, L\u003cJSON::XS\u003e\nor L\u003cJSON::PP\u003e will encode them as numbers (barewords) producing invalid JSON.\n\n print encode_json([9**9**9, -sin 9**9**9]);\n # Mojo::JSON or Cpanel::JSON::XS \u003e= 3.0112: [\"inf\",\"nan\"] (on Linux)\n # JSON::XS or JSON::PP: [inf,nan]\n\n=head2 Upgraded Numbers\n\nL\u003cJSON::MaybeXS\u003e, if using L\u003cJSON::XS\u003e, will attempt to guess if a value to be\nencoded is numeric or string based on whether Perl has ever populated a string\nvalue for it internally. Therefore, using a variable containing C\u003c13\u003e in a\nstring context will cause it to be encoded as C\u003c\"13\"\u003e even if the variable\nitself was not changed. L\u003cMojo::JSON\u003e, L\u003cJSON::PP\u003e version 2.92 or greater, or\nL\u003cCpanel::JSON::XS\u003e version 3.0109 or greater will encode C\u003c13\u003e as C\u003c13\u003e\nregardless of whether it has been used as a string.\n\n my ($num1, $num2) = (13, 14);\n my $str = \"$num1\";\n print encode_json([$num1, $num2, $str]);\n # Mojo::JSON, JSON::PP \u003e= 2.92, Cpanel::JSON::XS \u003e= 3.0109: [13,14,\"13\"]\n # JSON::XS: [\"13\",14,\"13\"]\n\n=head2 Duplicate Keys\n\nL\u003cMojo::JSON\u003e, L\u003cJSON::XS\u003e, and L\u003cJSON::PP\u003e will silently accept duplicate keys\nin the same JSON object when decoding a JSON string. L\u003cCpanel::JSON::XS\u003e\nversion 3.0235 or greater will throw an exception if duplicate keys are\nencountered. L\u003cCpanel::JSON::XS\u003e version 4.09 or greater will have the option\nset to once again accept duplicate keys.\n\n print dumper decode_json('{\"foo\":1, \"bar\":2, \"foo\":3}');\n # Mojo::JSON, JSON::XS, or JSON::PP: { bar =\u003e 2, foo =\u003e 3 }\n # Cpanel::JSON::XS \u003e= 3.0235 and \u003c 4.09: \"Duplicate keys not allowed\" exception\n\n=head1 BUGS\n\nThis is a monkey-patch of one of a few possible modules into another, and they\nhave incompatibilities, so there will probably be bugs. Report any issues on\nthe public bugtracker.\n\n=head1 AUTHOR\n\nDan Book, C\u003cdbook@cpan.org\u003e\n\n=head1 CREDITS\n\nSebastian Riedel, author of L\u003cMojolicious\u003e, for basic implementation.\n\n=head1 COPYRIGHT AND LICENSE\n\nCopyright 2014, Dan Book.\n\nThis library is free software; you may redistribute it and/or modify it under\nthe terms of the Artistic License version 2.0.\n\n=head1 SEE ALSO\n\nL\u003cMojo::JSON\u003e, L\u003cJSON::MaybeXS\u003e, L\u003cCpanel::JSON::XS\u003e, L\u003cJSON::XS\u003e, L\u003cJSON::PP\u003e\n\n=cut\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrinnz%2Fmojo-json-maybexs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrinnz%2Fmojo-json-maybexs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrinnz%2Fmojo-json-maybexs/lists"}