http://qs1969.pair.com?node_id=11125336


in reply to search json for key with particular value

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 )