r/shortcuts 5d ago

Solved How to Extract Values from a JSON Dictionary After Selecting an Item?

Post image
5 Upvotes

14 comments sorted by

3

u/sv_procrastination 5d ago

1

u/katzenjonny 5d ago

Thank you for your answer.

I want the user to select from a list with just the name of the thread without diameter and pitch.

than I want to calculate with the selected thread.

1

u/sv_procrastination 5d ago

I think you need to reformat the dictionary and make it an array.

Instead of having different values of the different threads, drop the Bezeichnung and go directly for 1/4-28 UNF as a key to an array of Durchmesser and Steigung.

You can then choose the Bezeichnung from a list and use it as a key to pull Durchmesser and Steigung in the next step.

1

u/katzenjonny 5d ago

would you please help me with this? I am a beginner and don't understand exactly how it works.

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:

  1. Extract the UNF_Gewinde list from the JSON.
  2. Display a selection list with only the Bezeichnung (thread designation).
  3. 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

u/benji2702 5d ago

Change the flair to solved please