about summary refs log tree commit homepage
path: root/lib/PublicInbox/Config.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PublicInbox/Config.pm')
-rw-r--r--lib/PublicInbox/Config.pm12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index d2010f7a..039eb445 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -488,4 +488,16 @@ sub urlmatch {
         }
 }
 
+sub json {
+        state $json;
+        $json //= do {
+                for my $mod (qw(Cpanel::JSON::XS JSON::MaybeXS JSON JSON::PP)) {
+                        eval "require $mod" or next;
+                        # ->ascii encodes non-ASCII to "\uXXXX"
+                        $json = $mod->new->ascii(1) and last;
+                }
+                $json;
+        };
+}
+
 1;