{"id":1615,"date":"2021-08-22T16:59:55","date_gmt":"2021-08-22T16:59:55","guid":{"rendered":"https:\/\/the-plot.com\/blog\/?p=1615"},"modified":"2021-08-22T17:14:01","modified_gmt":"2021-08-22T17:14:01","slug":"ios-shortcuts-get-dictionary-value-and-working-with-json","status":"publish","type":"post","link":"https:\/\/the-plot.com\/blog\/?p=1615","title":{"rendered":"iOS Shortcuts: Get Dictionary Value and working with JSON"},"content":{"rendered":"\n<p>&#8230;or &#8216;two hours of my life I&#8217;m not getting back as a result of a daft mistake&#8217; :).<\/p>\n\n\n\n<p>I&#8217;ve just spent a frustrating \/ puzzling afternoon trying unsuccessfully to parse a JSON dictionary from my own API, using the &#8216;Get Dictionary Value&#8217; action in Shortcuts. From what I can see, the documentation makes the normally safe assumption that you are working with an API that sets the appropriate content-type for JSON.<br><br>I wasn&#8217;t, because I&#8217;m using Flask, which defaults to text\/html. The API endpoints I&#8217;m using are a couple of years old and, up until today, I&#8217;ve been parsing the JSON using both JavaScript and <a href=\"https:\/\/the-plot.com\/blog\/?p=1536\">Objective-C<\/a>, neither of which are precious about the mime type. Hence the misconfiguration was at the bottom of my list of things to think about. <\/p>\n\n\n\n<p>Back to the shortcut action, the dictionary parsing was just failing silently. I went around the houses on the problem, and when I was working my way through a tutorial that used an external API, I noticed that the JSON result that I got back from hitting the &#8216;Play&#8217; button for the URL content rendered in a different type of UI element. Your mileage may vary on the appearance, but in dark mode (iOS 14), it renders as a black box. &#8216;Text\/html&#8217; renders as what looks like a webview, on a white background &#8211; which makes perfect retrospective sense, as it&#8217;s expecting it to be browser content. <br><br>Having figured this out, I then jumped on another merry-go-round, trying to avoid &#8216;double parsing&#8217; &#8211; escaped quotes &#8211; on a dictionary constructed from variables with the jsonify() method. The data has actually a pretty torturous path before it&#8217;s converted to JSON &#8211; Flask app  route calls an external python script which itself shells out &#8211; so I gave up on trying to do it &#8216;right&#8217;. As I need to serve html as well as JSON from the same server instance, I went with <a href=\"https:\/\/stackoverflow.com\/questions\/11773348\/python-flask-how-to-set-content-type\">this option<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8230;or &#8216;two hours of my life I&#8217;m not getting back as a result of a daft mistake&#8217; :). I&#8217;ve just spent a frustrating \/ puzzling afternoon trying unsuccessfully to parse a JSON dictionary from my own API, using the &#8216;Get &hellip; <a href=\"https:\/\/the-plot.com\/blog\/?p=1615\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1615","post","type-post","status-publish","format-standard","hentry","category-tech"],"_links":{"self":[{"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1615","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1615"}],"version-history":[{"count":3,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1615\/revisions"}],"predecessor-version":[{"id":1619,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1615\/revisions\/1619"}],"wp:attachment":[{"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}