{"id":1151,"date":"2022-04-09T14:20:12","date_gmt":"2022-04-09T19:20:12","guid":{"rendered":"https:\/\/www.brunerd.com\/blog\/?p=1151"},"modified":"2022-04-22T16:12:45","modified_gmt":"2022-04-22T21:12:45","slug":"improvisational-jpt-processing-apple-developer-json-transcript-files","status":"publish","type":"post","link":"https:\/\/www.brunerd.com\/blog\/2022\/04\/09\/improvisational-jpt-processing-apple-developer-json-transcript-files\/","title":{"rendered":"Improvisational jpt: Processing Apple Developer JSON transcript files"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">If you&#8217;ve downloaded the <a href=\"https:\/\/apps.apple.com\/us\/app\/apple-developer\/id640199958\" target=\"_blank\" rel=\"noreferrer noopener\">Developer app<\/a> for the Mac there&#8217;s a trove of JSON transcripts cached in <em>your<\/em> home folder at <code>~\/Library\/Group Containers\/group.developer.apple.wwdc\/Library\/Caches\/Transcripts<\/code> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Being curious I took a look at them using my JSON Power Tool<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/brunerd\/jpt\" target=\"_blank\"> jpt<\/a>. In it&#8217;s default mode it will &#8220;pretty print&#8221; JSON or in Javascript parlance &#8220;stringify&#8221; them with a two space indent per nesting level. Inside it can be seen the transcripts are arrays of arrays inisde a uniquely named object. The 1st entry of the array is the time in seconds and the 2nd entry is the string we want. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"531\" src=\"https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-2-1024x531.png\" alt=\"\" class=\"wp-image-1154\" srcset=\"https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-2-1024x531.png 1024w, https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-2-300x156.png 300w, https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-2-768x398.png 768w, https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-2-1140x592.png 1140w, https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-2.png 1142w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>Arrays of arrays<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">One of jpt&#8217;s cool features is that it supports the venerable yet nascent <a rel=\"noreferrer noopener\" href=\"https:\/\/datatracker.ietf.org\/wg\/jsonpath\/about\/\" target=\"_blank\">JSONPath<\/a> query syntax. Using JSONPath we can use the recursive operator <code>..<\/code> to go straight to the <code>transcript<\/code> object without needing determine the unique name of the parent object, then we want all the array within there <code>[*]<\/code>and inside those array we want the second entry of the 0 based array <code>[1]<\/code>. The query looks like this <code>$..transcript[*][1]<\/code> <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"810\" height=\"212\" src=\"https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-3.png\" alt=\"\" class=\"wp-image-1155\" srcset=\"https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-3.png 810w, https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-3-300x79.png 300w, https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-3-768x201.png 768w\" sizes=\"auto, (max-width: 810px) 100vw, 810px\" \/><\/a><figcaption>Just text please<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The query is single quoted so the shell doesn&#8217;t interpret the <code>$<\/code> as the beginning of a variable name. The <code>-T<\/code> option for jpt it outputs text without quotes. The default output mode for jpt is JSON (double quoted strings). I added all sorts of other niceties to the script, as you&#8217;ll see below. The results are output to your <code>~\/Desktop<\/code> in a folder called <code>Developer Transcripts<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code language-shell\"><code>#!\/bin\/bash\n: &lt;&lt;-LICENSE_BLOCK\nDeveloper Transcript Extractor Copyright (c) 2022 Joel Bruner. Licensed under the MIT License. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and\/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\nLICENSE_BLOCK\n\n############\n# VARIABLES #\n############\n\ndestinationFolderName=\"Developer Transcripts\"\ndestinationPath=\"${HOME}\/Desktop\/${destinationFolderName}\"\n\n#you'll need to download the Developer app and launch it: https:\/\/apps.apple.com\/us\/app\/apple-developer\/id640199958\ntranscriptPaths=$(find \"${HOME}\/Library\/Group Containers\/group.developer.apple.wwdc\/Library\/Caches\/Transcripts\/ByID\" -name '*json')\ncontentsJSON=\"${HOME}\/Library\/Group Containers\/group.developer.apple.wwdc\/Library\/Caches\/contents.json\"\n\n########\n# MAIN #\n########\n\n#either jpt should be installed or the function jpt.min can be pasted in here\nif ! which jpt &amp;&gt;\/dev\/null; then\n\techo \"Please install jpt or embed jpt.min in this script: https:\/\/github.com\/brunerd\/jpt\"\n\texit 1\nfi\n\n#ensure the destination folder exists\n&#91; ! -d \"${destinationPath}\" ] &amp;&amp; mkdir \"${destinationPath}\"\n\n#ignore spaces in file paths\nIFS=$'\\n'\n\n#loop through each transcript json file\nfor transcriptPath in ${transcriptPaths}; do\n\t#id is just the file name without the path and extension\n\tid=$(cut -d. -f1 &lt;&lt;&lt; \"${transcriptPath##*\/}\")\n\t#a couple of nice-to-haves\n\ttitle=$(jpt -T '$.contents&#91;?(@.id == \"'\"${id}\"'\")].title' \"${contentsJSON}\")\n\tdescription=$(jpt -T '$.contents&#91;?(@.id == \"'\"${id}\"'\")].description' \"${contentsJSON}\")\n\t#change \\ (disallowed in Unix) to : (Disallowed in Finder byt allowed in Unix)\n\ttitle=${title\/\/\\\/\/:}\n\turl=$(jpt -T '$.contents&#91;?(@.id == \"'\"${id}\"'\")].webPermalink' \"${contentsJSON}\")\n\n\t#\"wwdc\" always has the year in the id but not tech-talks or insights\n\tif ! grep -q -i wwdc &lt;&lt;&lt; \"$id\"; then\n\t\tyear=\"$(jpt '$.contents&#91;?(@.id == \"'\"${id}\"'\")].originalPublishingDate' \"${contentsJSON}\" | date -j -r 1593018000 +\"%Y\")-\"\n\t\tfilename=\"${year}${id} - ${title}.txt\"\n\telse\n\t\tfilename=\"${id} - ${title}.txt\"\n\tfi\n\n\t#put the ID and Title, the URL and Description at the top of the transcript\n\techo \"${id} - ${title}\" &gt; \"${destinationPath}\"\/\"${filename}\"\n\techo -e \"${url}\\n\" &gt;&gt; \"${destinationPath}\"\/\"${filename}\"\n\techo -e \"Description:\\n${description}\\n\\nTranscript:\" &gt;&gt; \"${destinationPath}\"\/\"${filename}\"\n\t\n\t#append the transcript extract\n\tjpt -T '$..transcript&#91;*]&#91;1]' \"${transcriptPath}\" &gt;&gt; \"${destinationPath}\"\/\"${filename}\"\n\n\t#just echo out our progress\n\techo \"${destinationPath}\"\/\"${filename}\"\ndone\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The final result is sortable folder of text files that you can easily QuickLook through.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"407\" src=\"https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-4-1024x407.png\" alt=\"\" class=\"wp-image-1159\" srcset=\"https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-4-1024x407.png 1024w, https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-4-300x119.png 300w, https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-4-768x306.png 768w, https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-4.png 1146w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Some serviceably readable contents!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-6.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"633\" src=\"https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-6-1024x633.png\" alt=\"\" class=\"wp-image-1163\" srcset=\"https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-6-1024x633.png 1024w, https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-6-300x185.png 300w, https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-6-768x474.png 768w, https:\/\/www.brunerd.com\/blog\/wp-content\/uploads\/image-6.png 1240w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So there you go! Some surprise JSON transcript files from the <a rel=\"noreferrer noopener\" href=\"https:\/\/apps.apple.com\/us\/app\/apple-developer\/id640199958\" target=\"_blank\">Apple Developer app<\/a>, made me wonder how someone would turn them into human readable files. It turned out it was a fun and practical use of <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/brunerd\/jpt\" target=\"_blank\">jpt<\/a> and it&#8217;s support for JSONPath. You can download an installer package from the <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/brunerd\/jpt\/releases\" target=\"_blank\">Releases<\/a> page to try it out.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve downloaded the Developer app for the Mac there&#8217;s a trove of JSON transcripts cached in your home folder at ~\/Library\/Group Containers\/group.developer.apple.wwdc\/Library\/Caches\/Transcripts Being curious I took a look at them using my JSON Power Tool jpt. In it&#8217;s default mode it will &#8220;pretty print&#8221; JSON or in Javascript parlance &#8220;stringify&#8221; them with a two [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,19,37,51,41,12],"tags":[],"class_list":["post-1151","post","type-post","status-publish","format-standard","hentry","category-apple","category-bash","category-jpt","category-json","category-jsonpath","category-scripting"],"_links":{"self":[{"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/posts\/1151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/comments?post=1151"}],"version-history":[{"count":11,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/posts\/1151\/revisions"}],"predecessor-version":[{"id":1169,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/posts\/1151\/revisions\/1169"}],"wp:attachment":[{"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/media?parent=1151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/categories?post=1151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.brunerd.com\/blog\/wp-json\/wp\/v2\/tags?post=1151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}