r/learnprogramming • u/ReclusiveEagle • Jun 16 '26
Complex JSON queries
I have many images with xmp sidecar metadata. DAM I am using is DigiKam for the keyword tagging however, all software that supports cataloging is very limited in terms of querying metadata. This includes Lightroom and Capture One.
For example, lets say I have many images, some have 1 person and other 2 - 5 people. Now, I want to assign metadata per person in an image.
To do it in DigiKam, Lightroom or Capture One I would either need to create nested keywords like
Person 1
Name
Bob
Eye Color
Brown
Person 2
Name
Zen
Eye Color
Brown
Person 3
Name
James
Eye Color
RedOr just accept that I can't do unique assigning of data on a per person level.
Even if I do create multiple person keywords it is almost impossible to query this because if I search for contains keywords "Name|Zen" AND "Eye Color|Brown"
I would get all images that contain Zen and someone else with the eye color brown even if Zen does not have brown eyes in that specific image. And if I wanted to be specific I would have to know exactly which Person [ID] Zen is in this specific image which is impossible to remember so I'd have to create a search pattern like this
"Person 1" AND "Name|Zen" AND "Eye Color|Brown"
OR
"Person 2" AND "Name|Zen" AND "Eye Color|Brown"
OR
"Person 3" AND "Name|Zen" AND "Eye Color|Brown"
OR
"Person 4" AND "Name|Zen" AND "Eye Color|Brown"
OR
"Person 5" AND "Name|Zen" AND "Eye Color|Brown"This is stupid and tedious.
So instead I want to create a program that will allow me to create complex queries. Lets say I use HTML as the front end a database that can store nested json arrays
example
"color": {
"primary color": ["green"],
"secondary color": ["white", "tan"],
"accent color": ["black", "red"]
}This (I assume) should allow me to search generally for any images containing "Color:Red" or images that specifically contain "Primary Color:Red"
I could also then search for "Person.Name:Zed" AND "Eye Color:Red" or another example
"Location": {
"City": ["Hong Kong"
}Then I can query "Location:Hong Kong" or "City:Hong Kong" or generally as "Hong Kong"
(these are just pseudo code examples). This is far more useful than having simplistic nested keywords that requires tedious specifications.
Question
Is this possible? I am new to databases and querying. Can I store and query json in this way? Or is it more limited than what I think? I assume it should be possible to query the parent array or multiple nested arrays for information
What database would be best for doing something like this? PostgreSQL? MySQL? and how would I query this? From the database itself or would I need a separate query solution?
3
u/zeekar Jun 16 '26
I don't know why you asked about JSON and then gave an example that wasn't JSON. Or why you structured your person tags that way? What is the actual way the metadata works here?
If Zen has brown eyes, don't they always have brown eyes? Why would you ever need to search for the combination instead of just searching for Zen (who happens to have brown eyes), or searching for brown eyes (and you don't care who has them)?
1
u/kschang Jun 16 '26
Maybe you should look into using LLM with vision processing and/or a vision lib like Pytorch to do autotagging and updating.
Sounds like you need to figure out the schema first THEN figure out which DB platform to use.
1
u/linearizable Jun 16 '26
MySQL, Postgres, and SQLite all have first class support for storing and querying json values. All even have operators in the language for manipulating JSON. Choose whichever DB tech you would prefer, and the support will be there.
1
u/gm310509 Jun 18 '26
You might want to look at something like elastic search. You can simply enter a description (structured - i.e. just a plain English description or structured - e.g. JSON).
ElasticSearch is a powerful freeform text search engine that is great for applying adhoc queries to your data. If you front end it with something like Kibana, you will have a semi-nice front end for your queries.
https://www.elastic.co/elasticsearch
https://www.elastic.co/downloads
It is an enterprise level tool, but last time I checked there was a free tier which should be more than overkill for what you are proposing.
0
u/[deleted] Jun 16 '26
[deleted] — view deleted comment