aboutsummaryrefslogtreecommitdiffstats
path: root/lib/WWW/FairViewer/ParseJSON.pm
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2021-07-09 15:27:16 -0500
committerJesús <heckyel@hyperbola.info>2021-07-09 15:27:16 -0500
commit739c821a54c01816e60eb5f774c8977a1e221ea0 (patch)
treee04a7f5a6fe4d450d43fd45c412f9d415bcb7a7e /lib/WWW/FairViewer/ParseJSON.pm
parentc1322a4e9a1fb0a286dab1277a740072d0ab30f9 (diff)
downloadfair-viewer-739c821a54c01816e60eb5f774c8977a1e221ea0.tar.lz
fair-viewer-739c821a54c01816e60eb5f774c8977a1e221ea0.tar.xz
fair-viewer-739c821a54c01816e60eb5f774c8977a1e221ea0.zip
upstream
Diffstat (limited to 'lib/WWW/FairViewer/ParseJSON.pm')
-rw-r--r--lib/WWW/FairViewer/ParseJSON.pm12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/WWW/FairViewer/ParseJSON.pm b/lib/WWW/FairViewer/ParseJSON.pm
index 4945a2a..6733eb0 100644
--- a/lib/WWW/FairViewer/ParseJSON.pm
+++ b/lib/WWW/FairViewer/ParseJSON.pm
@@ -23,6 +23,18 @@ Parse a JSON string and return a HASH ref.
=cut
+sub parse_utf8_json_string {
+ my ($self, $json) = @_;
+
+ if (not defined($json) or $json eq '') {
+ return {};
+ }
+
+ require JSON;
+ my $hash = eval { JSON::from_json($json) };
+ return $@ ? do { warn "[JSON]: $@\n"; {} } : $hash;
+}
+
sub parse_json_string {
my ($self, $json) = @_;