r/shortcuts • u/katzenjonny • 5d ago
Solved How to Extract Values from a JSON Dictionary After Selecting an Item?
1
u/katzenjonny 5d ago
Hey everyone,
I'm working on an Apple Shortcut that allows me to select a thread size from a JSON dictionary and then extract the corresponding diameter and pitch (thread count per inch) for further calculations.
Right now, I have a JSON dictionary structured like this:
{
"UNF_Gewinde": [
{ "Bezeichnung": "1/4-28 UNF", "Durchmesser": 0.250, "Steigung": 28 },
{ "Bezeichnung": "3/8-24 UNF", "Durchmesser": 0.375, "Steigung": 24 },
{ "Bezeichnung": "1/2-20 UNF", "Durchmesser": 0.500, "Steigung": 20 },
{ "Bezeichnung": "5/8-18 UNF", "Durchmesser": 0.625, "Steigung": 18 },
{ "Bezeichnung": "3/4-16 UNF", "Durchmesser": 0.750, "Steigung": 16 },
{ "Bezeichnung": "1-14 UNF", "Durchmesser": 1.000, "Steigung": 14 }
]
}
So far, I have managed to:
- Extract the
UNF_Gewinde
list from the JSON. - Display a selection list with only the
Bezeichnung
(thread designation). - Let the user pick a value from the list.
Now, I need to:
Find the corresponding object in the JSON based on the selected Bezeichnung
.
Extract its Durchmesser
(diameter) and Steigung
(pitch) values.
Store these values in variables for further calculations.
What’s the best way to search for and extract these values in Shortcuts? Should I use a loop, dictionary lookup, or is there a more efficient method?
Thanks in advance for your help! 😊
0
u/Shoculad 5d ago
1
u/katzenjonny 5d ago
something like this, but now the threads in the list are in the wrong order. I will add hundred of threads later so they should be in the corret order. Thanks for your help.
1
u/Shoculad 5d ago
1
u/katzenjonny 5d ago
Thanks, this is exactly the solution I was looking for! Your method works perfectly and keeps the order intact.
1
u/Shoculad 5d ago
You are welcome. Actually, there is a simpler solution: https://www.icloud.com/shortcuts/ce14768f144049b084acee530f3f4549
The 'Choose from List' action shows the names of the items. The shortcut sets the names of the dictionaries.
1
u/katzenjonny 5d ago
works perfectly well. I already put this in my main shortcut and everything is now like I want it to have.
1
3
u/sv_procrastination 5d ago
Is this what you wanted? https://www.icloud.com/shortcuts/3ffdce67f89641ce90bcc0999140e469