Not a perl answer, and probably not even useful for the OP, unless the JSON is large/many, and a database is at hand.
Nevertheless, and Just For Fun: indexed JSON in PostgreSQL:
--> show rowcount of the test table:
db=# select count(*) from myjsonfile100k ;
count
--------
790000
(1 row)
--> show size of the test table, and index:
db=# \dti+ myjsonfile100k*
List of relatio
+ns
Schema | Name | Type | Owner | T
+able | Persistence | Size | Description
--------+-----------------------------------+-------+----------+------
+----------+-------------+--------+-----------------------
public | myjsonfile100k | table | aardvark |
+ | permanent | 589 MB |
public | myjsonfile100k_js_pathops_gin_idx | index | aardvark | myjso
+nfile100k | permanent | 135 MB |
public | myjsonfile100k_pkey | index | aardvark | myjso
+nfile100k | permanent | 17 MB |
(3 rows)
--> show table+index structure
db=# \d+ myjsonfile100k
Table "public.myjsonfi
+le100k"
Column | Type | Collation | Nullable | Default
+ | Storage | Stats target | Description
--------+---------+-----------+----------+----------------------------
+----------------+----------+--------------+-------------
js | jsonb | | |
+ | extended | |
id | integer | | not null | nextval('myjsonfile100k_id_
+seq'::regclass) | plain | |
Indexes:
"myjsonfile100k_pkey" PRIMARY KEY, btree (id)
"myjsonfile100k_js_pathops_gin_idx" gin (js jsonb_path_ops)
Access method: heap
--> show single jsonb 'record' structure:
db=# select jsonb_pretty(js) from myjsonfile100k limit 1;
jsonb_pretty
+
----------------------------------------------------------------------
+---------------------------------
{
+ +
"bool": false,
+ +
"city": "Cebu City",
+ +
"date": "1980-08-12",
+ +
"enum": "generator",
+ +
"array": [
+ +
"Eve",
+ +
"Chandra",
+ +
"Binny",
+ +
"Tabbatha",
+ +
"Anallese"
+ +
],
+ +
"regEx": "hellooooooooooooooooooooooooooooooooooooooooooooooooooo
+ooooooooooooooooooooooo to you",+
"random": 11,
+ +
"country": "Iran, Islamic Republic Of",
+ +
"lastname": "Seligman",
+ +
"firstname": "Correy",
+ +
"countryCode": "DE",
+ +
"random float": 60.823,
+ +
"array of objects": [
+ +
{
+ +
"index": 0,
+ +
"index start at 5": 5
+ +
},
+ +
{
+ +
"index": 1,
+ +
"index start at 5": 6
+ +
},
+ +
{
+ +
"index": 2,
+ +
"index start at 5": 7
+ +
}
+ +
],
+ +
"email from expression": "Correy.Seligman@yopmail.com",
+ +
"email uses current data": "Correy.Seligman@gmail.com"
+ +
}
(1 row)
--> crunch time:
--> (NOTE that below I truncated the result rows with '...' for PM
+-display):
db=# select
id
, js->>'firstname' as fname
, js->>'lastname' as lname
, *
from myjsonfile100k
where js @> '{"firstname": "Lilith"}' -- nevermind the crazy names,
and js @> '{"lastname": "Trace"}' -- randomly generated stuff
;
id | fname | lname |
+
+
--------+--------+-------+--------------------------------------------
+----------------------
127245 | Lilith | Trace | {"bool": false, "city": "Kolkata", "date":
+"1995-05-14", "enum": ...
393835 | Lilith | Trace | {"bool": true, "city": "Sarajevo", "date":
+"1987-06-07", "enum": ...
(2 rows)
Time: 0.846 ms
--> less than a millisecond
All this is in released PostgreSQL, i.e., postgres 13.
But JSON indexing in postgres is still an area of intensive development - more JSON flexibility is in the dev pipeline)
(TWIMC, for future tech detail (PDFs, sometimes rather low-level):
http://www.sai.msu.su/~megera/postgres/talks )
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.