Skip to content

Commit

Permalink
update to SecJson.pm
Browse files Browse the repository at this point in the history
  • Loading branch information
Risto Vaarandi committed Nov 19, 2021
1 parent 2a38d47 commit 3055daa
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions parsing-json/SecJson.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ our @ISA = qw(Exporter);
our $VERSION = 1.00;
our @EXPORT_OK = qw(json2matchvar);

# this module needs the perl JSON module for parsing json input
# this module needs the perl Cpanel::JSON::XS module for parsing json input

use JSON;
use Cpanel::JSON::XS;

sub flatten {
my($ref, $ret, $prefix) = @_;
Expand Down Expand Up @@ -85,7 +85,10 @@ sub flatten {
# (a) digits only (e.g., $1)
# (b) the first character is a letter or underscore, while the following
# characters can be alphanumerals, underscores and exclamation marks
# (e.g., $+{_inputsrc} or $+{myvar})
# (e.g., $+{myvar}). However, when creating named match variables from
# a JSON input string, it is recommended to begin the variable name with
# a letter, since names of special automatically created variables begin
# with an underscore (e.g., $+{_inputsrc}).

sub json2matchvar {
my($json_line, $prefix) = @_;
Expand All @@ -96,9 +99,10 @@ sub json2matchvar {

# mimic the default behavior of SEC input processing where Perl wide
# characters are not created from utf8 encoded characters (for enabling
# this behavior, use JSON::decode_json() instead of JSON::from_json())
# this behavior, use Cpanel::JSON::XS->new->utf8->decode() instead of
# Cpanel::JSON::XS->new->decode())

$ptr = JSON::from_json($json_line);
$ptr = Cpanel::JSON::XS->new->decode($json_line);
$matchvar_hash = {};

flatten($ptr, $matchvar_hash, $prefix);
Expand Down

0 comments on commit 3055daa

Please sign in to comment.