Is there anyway to find the closest matching JSON entry inside a database
Just a rough sketch on how you could do that with Postgres arrays.

There are two array operators that you might be interested in. The "overlaps" operator that returns true if some of the elements are the same and the "contains" operator that checks if all elements of one array are contained in the other - that would be your 100% match: 

Assuming this table: 

create table idlist (ids int[]);


You can create an index on that column:

create index on idlist using gin (ids);


A query to find the 100% match looks like this:

select *
from idlist
where ids @&gt; array[1,2,3,4,5,6]


That will return only rows where ids contains all the values 1,2,3,4,5,6 (but it might contain more). 

On a table with 2 million rows and arrays from 5 to 100 elements this takes about 20ms on a pretty old test server (the actual runtime depends on the total amount of matches found)

The query to find rows that contain at least one of the values of the parameter uses the &amp;&amp; operator and is substantially slower.

select *
from idlist
where ids &amp;&amp; array[1,2,3,4,5,6];


That takes about 300ms on my test server. But it also returns 500.000 rows! If the condition only returns very few rows (less than thousand) then obviously this is going to be a lot faster. 

How you proceed from there is a matter on how restrictive the conditions are that you use. If the &amp;&amp; operator only returns a few rows (not half a million) then maybe processing them in your application might be more efficient. 

Getting the information if the input parameter is completely contained, could be done like this:

select ids, 
       ids @&gt; array[1,2,3,4,5,6] as full_match
from idlist
where ids &amp;&amp; array[1,2,3,4,5,6];


Another option would be to write your own function that calculates the match, or maybe use the intarray extension to efficiently calculate the intersection between two arrays.