in reply to Need something like a SQL query for JSON data structures (JSON::XS)
If you read your data with JSON, you can use grep in the intended way, see below. However, the SQL you provided would not return any records for the example data as none of the fields equals 'taco'. So I have been using matching instead of test for equality below and I am testing only two fields. HTH.
use strict; use warnings; use Data::Dumper; use JSON; my $json = <<'JSON'; { "People" : [ { "name" : "bob", "title" : "janitor", "email" : "taco@blah.com", "iq" : "180", "favorite_food" : "wagyu steak" }, { "name" : "joe", "title" : "software engineer", "email" : "", "iq" : "80", "favorite_food" : "raw hamburger" }, { "name" : "sandy", "title" : "dishwasher", "email" : "", "iq" : "240", "favorite_food" : "tacos" }, { "name" : "george", "title" : "software engineer", "email" : "", "iq" : "14", "favorite_food" : "tacos" } ] } JSON my $j = JSON->new->decode($json); my @results2 = grep { $_->{email} =~ /taco/ or $_->{favorite_food} =~ +/taco/ } @{ $j->{People} }; print Dumper \@results2;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need something like a SQL query for JSON data structures (JSON::XS)
by walkingthecow (Friar) on Sep 06, 2013 at 06:07 UTC | |
by Laurent_R (Canon) on Sep 06, 2013 at 06:17 UTC | |
by walkingthecow (Friar) on Sep 06, 2013 at 06:25 UTC |