Saving and loading parts of configuration
How about storing your data in sqlite database? All of your operations can be implemented as relational database queries/commands.

Your table will have columns:


FIRST
SECOND
FIRST_ID
SECOND_ID


To perform updates on the second_id based on an object, just use (this is pseudo-code):

for (second in input_json) {
  ...run UPDATE CONFIGS SET SECOND_ID = {input_json[second]} WHERE SECOND = {second} ...


You can make this run efficiently by creating an index on the SECOND column.

Lookup are just SELECT * FROM CONFIGS WHERE ...

For instance, to select only those configs which have second id:

SELECT * FROM CONFIGS WHERE SECOND_ID &lt;&gt; ""


It all depends on how many configs you have. For a large number using a sqlite database could be a win.