PrePAN

Sign in to PrePAN

JSON::Response::Inspector Perform introspection on the data structure returned by a JSON request

Author
sdondley@github
Date
URL
Status
In Review
Good

Synopsis

```
use Data::Dump qw( pp );

sub introspect {
  my ($data, $output) = @_;

  if (ref $data eq 'ARRAY') {
    my $sub_out = ($output->{'ARRAY'} //= {});
    introspect($_, $sub_out) for @{ $data };
  }

  elsif (ref $data eq 'HASH') {
    my $hash_out = $output->{"HASH"} //= {};
    for my $key (keys %$data) {
      my $sub_out = ($hash_out->{"$key"} //= {});
      introspect($_, $sub_out) for $data->{$key};
    }
  }

  elsif (ref $data) {
    #$output->{ref($data).'REF'}=1;
  }

  else {
    #$output->{SCALAR}=1;
    undef $output;

  }
}

my %out;

my $output = introspect($json_data_converted_perl, \%out);
pp $output;
```

Description

I'm trying to determine if something like this already exists. If not, I'll create a module for this function. See https://perlmonks.org/?node_id=1222269 for background and to see what this code outputs.

The module will help developers quickly assess json (or any other data structure) responses. It will print out a "merge" of each element in the data structure, without the actual data, so the developer can see all the fields at a glance to see the structure of the response.

Comments

anonymouse
Anonymous
there's plenty of tools that do this, though i'm not sure if any are in perl or on cpan. here's one: https://github.com/ilyash/show-struct

If you really need it in perl and on cpan, I'd consider renaming it to something like App::JSON::Inspector
Why under "App?"
anonymouse
Anonymous
https://pause.perl.org/pause/query?ACTION=pause_namingmodules#App

Please sign up to post a review.