How to Parse JSON in iOS 12 Shortcuts
Parsing JSON in iOS 12 Shortcuts allows you to extract specific data from web APIs and use it in your automated workflows. By retrieving the raw response using a network request action, iOS automatically handles the payload as a structured dictionary, enabling you to isolate key-value pairs, navigate nested objects, and loop through arrays using native dictionary actions.
Step 1: Make the API Request
To retrieve the JSON data, you first need to perform an HTTP request:
- Open the Shortcuts app on your iOS 12 device.
- Create a new shortcut or edit an existing one.
- Add the URL action and enter the API endpoint URL.
- Add the Get Contents of URL action immediately after the URL action.
- If required by the API, expand the Advanced section to configure HTTP methods (GET, POST, etc.), headers, or a request body.
Step 2: Convert the Response to a Dictionary
iOS 12 automatically interprets valid JSON text as a dictionary, but explicitly converting it ensures stability:
- Add the Get Dictionary from Input action directly beneath the Get Contents of URL action.
- This action takes the raw text or file response from the server and maps it into standard key-value pairs that the Shortcuts app can query.
Step 3: Extract Values by Key
Once your data is in a dictionary format, extract individual fields using keys:
- Add the Get Dictionary Value action.
- Set the Get parameter to
Value. - In the Key field, type the exact case-sensitive
name of the JSON key you want to retrieve (for example,
statusortemperature). - The output of this action will be the specific value associated with that key.
Step 4: Handle Nested JSON Objects
If the value you need is nested inside another object (for example,
{"user": {"name": "Alice"}}):
- Add a Get Dictionary Value action with the key set
to the parent object (
user). - Add a second Get Dictionary Value action directly
below it, setting the key to the child property
(
name). - The output will now be the inner value (
Alice).
Step 5: Handle JSON Arrays
When the JSON response contains an array of items (lists inside
brackets [...]):
- Use Get Dictionary Value to select the key containing the array.
- Add the Repeat with Each action to iterate through each item in the list.
- Inside the loop, use Get Dictionary Value to pull
specific fields from the current item variable
(
Repeat Item).
Step 6: Use the Extracted Data
Once the target data is isolated, you can pass it to other iOS 12 actions such as Show Result, Show Notification, Copy to Clipboard, or save it to a file using Save File.