Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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 (rather low-level): http://www.sai.msu.su/~megera/postgres/talks/json-build-2020.pdf )


In reply to [OT} Re: search json for key with particular value by erix
in thread search json for key with particular value by rahulruns

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (5)
    As of 2021-04-21 10:26 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?